Android開發(fā)實(shí)現(xià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ì)有所幫助。
- Android Studio設(shè)置或修改Android SDK路徑方法
- Android Intent傳遞數(shù)據(jù)大小限制詳解
- Android Studio Gradle依賴沖突解決方法
- Android開發(fā)之a(chǎn)ndroid_gps定位服務(wù)簡(jiǎn)單實(shí)現(xiàn)
- Android開發(fā)經(jīng)驗(yàn)談:并發(fā)編程(線程與線程池)(推薦)
- Android中Retrofit的簡(jiǎn)要介紹
- android分享純圖片到QQ空間實(shí)現(xiàn)方式
- Android權(quán)限如何禁止以及友好提示用戶開通必要權(quán)限詳解
- 史上最全Android build.gradle配置詳解(小結(jié))
- Android中再按一次退出提醒實(shí)現(xiàn)的兩種方法
相關(guān)文章
RecyclerView+CardView實(shí)現(xiàn)橫向卡片式滑動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了RecyclerView+CardView實(shí)現(xiàn)橫向卡片式滑動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01Android讀取本地照片和視頻相冊(cè)實(shí)例代碼
本篇文章主要介紹了Android讀取本地照片和視頻相冊(cè)實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06Android 阿里云OSS文件上傳的實(shí)現(xiàn)示例
這篇文章主要介紹了Android 阿里云OSS文件上傳的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08Android編程之利用服務(wù)實(shí)現(xiàn)電話監(jiān)聽的方法
這篇文章主要介紹了Android編程之利用服務(wù)實(shí)現(xiàn)電話監(jiān)聽的方法,較為詳細(xì)的分析了Android基于服務(wù)實(shí)現(xiàn)針對(duì)電話監(jiān)聽的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-11-11Android應(yīng)用程序模型之應(yīng)用程序,任務(wù),進(jìn)程,線程分析
這篇文章主要介紹了Android應(yīng)用程序模型之應(yīng)用程序,任務(wù),進(jìn)程,線程分析,較為詳細(xì)的分析了Android應(yīng)用程序模型中關(guān)于任務(wù)、進(jìn)程、線程的相關(guān)概念及注意事項(xiàng),需要的朋友可以參考下2016-01-01android內(nèi)存優(yōu)化之圖片優(yōu)化
對(duì)圖片本身進(jìn)行操作。盡量不要使用setImageBitmap、setImageResource、BitmapFactory.decodeResource來(lái)設(shè)置一張大圖,因?yàn)檫@些方法在完成decode后,最終都是通過(guò)java層的createBitmap來(lái)完成的,需要消耗更多內(nèi)存2012-12-12Android 中RecycleView實(shí)現(xiàn)item的點(diǎn)擊事件
這篇文章主要介紹了Android 中RecycleView實(shí)現(xiàn)item的點(diǎn)擊事件的相關(guān)資料,需要的朋友可以參考下2017-03-03Android apk 項(xiàng)目一鍵打包并上傳到蒲公英的實(shí)現(xiàn)方法
這篇文章主要介紹了Android apk 項(xiàng)目一鍵打包并上傳到蒲公英,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06Input系統(tǒng)之InputReader處理合成事件詳解
這篇文章主要為大家介紹了Input系統(tǒng)之InputReader處理合成事件詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11