怎么在Android中實(shí)現(xiàn)一個(gè)圓形圖片功能

怎么在Android中實(shí)現(xiàn)一個(gè)圓形圖片功能?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

成都創(chuàng)新互聯(lián)是專業(yè)的五臺(tái)網(wǎng)站建設(shè)公司,五臺(tái)接單;提供成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行五臺(tái)網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!

注:在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]);
      }
    });
  }
}

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。

網(wǎng)站標(biāo)題:怎么在Android中實(shí)現(xiàn)一個(gè)圓形圖片功能
標(biāo)題網(wǎng)址:http://muchs.cn/article16/pdjdgg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開(kāi)發(fā)、網(wǎng)站改版、做網(wǎng)站、手機(jī)網(wǎng)站建設(shè)定制網(wǎng)站、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)