欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)實(shí)現(xiàn)圓形圖片功能示例

 更新時(shí)間:2019年04月11日 11:58:30   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)圓形圖片功能,涉及Android實(shí)現(xiàn)圓形圖片的界面布局與CirImageView組件相關(guān)使用操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開發(fā)實(shí)現(xiàn)圓形圖片功能。分享給大家供大家參考,具體如下:

**絕對(duì)布局:通過(guò)直接給定控件起始坐標(biāo) ( x , y ) 和 ( w , l ) ,來(lái)生成控件。

圓形頭像:CircleImageView的使用 **

注:在build.gradle中添加:

implementation 'de.hdodenhof:circleimageview:1.3.0'

XML布局文件:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
  android:id="@+id/root"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".Home"
  android:layout_gravity="center">
  <!--定義一個(gè)文本框用于存放頭像,使用絕對(duì)布局-->
  <de.hdodenhof.circleimageview.CircleImageView
    android:id="@+id/imageview"
    android:layout_x="150dp"
    android:layout_y="75dp"
    android:layout_width="100dp"
    android:layout_height="100dp"/>
  <!--定義一個(gè)文本框,使用絕對(duì)定位-->
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="20dp"
    android:layout_y="225dp"
    android:text="用戶名:"/>
  <!--定義一個(gè)文本編輯框,使用絕對(duì)定位-->
  <EditText
    android:layout_x="80dp"
    android:layout_y="215dp"
    android:hint="郵箱/手機(jī)/用戶名"
    android:layout_width="wrap_content"
    android:width="275dp"
    android:layout_height="wrap_content"
    android:singleLine="true" />
  <!--定義一個(gè)文本框使用絕對(duì)定位-->
  <TextView
    android:layout_x="20dp"
    android:layout_y="285dp"
    android:text=" 密 碼 :"
    android:gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
  <!--定義一個(gè)文本編輯框,使用絕對(duì)定位-->
  <EditText
    android:layout_x="80dp"
    android:layout_y="275dp"
    android:hint="密碼/驗(yàn)證碼"
    android:layout_width="wrap_content"
    android:width="275dp"
    android:layout_height="wrap_content"
    android:password="true"
    android:singleLine="true" />
  <!--定義一個(gè)按鈕,使用絕對(duì)定位-->
  <Button
    android:layout_x="100dp"
    android:layout_y="350dp"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:text=" 登 錄 "/>
</AbsoluteLayout>

Java代碼 動(dòng)態(tài)設(shè)置頭像:

//點(diǎn)擊 切換圖片
public class Home extends AppCompatActivity {
  private LinearLayout mainLayout=null;
  private ImageView iv=null;
  //定義一個(gè)訪問(wèn)圖片的數(shù)組
  int[] images = new int[]{//放置你的圖片
      R.drawable.gass,
      R.drawable.gonzhixiaochou
  };
  //用于圖片切換
  int currenImg = 0;
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);//顯示manLayout
    //創(chuàng)建CirImageView組件
    final CircleImageView circleimageView01 = (CircleImageView) findViewById(R.id.imageview);
    //設(shè)置CirImageView背景
    circleimageView01.setImageResource(images[0]);
    circleimageView01.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        //切換背景
        circleimageView01.setImageResource(images[++currenImg % images.length]);
      }
    });
  }
}

效果:

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論