Android開發(fā)實現(xiàn)圓形圖片功能示例
本文實例講述了Android開發(fā)實現(xiàn)圓形圖片功能。分享給大家供大家參考,具體如下:
**絕對布局:通過直接給定控件起始坐標(biāo) ( x , y ) 和 ( w , l ) ,來生成控件。
圓形頭像: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">
<!--定義一個文本框用于存放頭像,使用絕對布局-->
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageview"
android:layout_x="150dp"
android:layout_y="75dp"
android:layout_width="100dp"
android:layout_height="100dp"/>
<!--定義一個文本框,使用絕對定位-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="225dp"
android:text="用戶名:"/>
<!--定義一個文本編輯框,使用絕對定位-->
<EditText
android:layout_x="80dp"
android:layout_y="215dp"
android:hint="郵箱/手機/用戶名"
android:layout_width="wrap_content"
android:width="275dp"
android:layout_height="wrap_content"
android:singleLine="true" />
<!--定義一個文本框使用絕對定位-->
<TextView
android:layout_x="20dp"
android:layout_y="285dp"
android:text=" 密 碼 :"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!--定義一個文本編輯框,使用絕對定位-->
<EditText
android:layout_x="80dp"
android:layout_y="275dp"
android:hint="密碼/驗證碼"
android:layout_width="wrap_content"
android:width="275dp"
android:layout_height="wrap_content"
android:password="true"
android:singleLine="true" />
<!--定義一個按鈕,使用絕對定位-->
<Button
android:layout_x="100dp"
android:layout_y="350dp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text=" 登 錄 "/>
</AbsoluteLayout>
Java代碼 動態(tài)設(shè)置頭像:
//點擊 切換圖片
public class Home extends AppCompatActivity {
private LinearLayout mainLayout=null;
private ImageView iv=null;
//定義一個訪問圖片的數(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ā)入門與進階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
- Android Studio設(shè)置或修改Android SDK路徑方法
- Android Intent傳遞數(shù)據(jù)大小限制詳解
- Android Studio Gradle依賴沖突解決方法
- Android開發(fā)之a(chǎn)ndroid_gps定位服務(wù)簡單實現(xiàn)
- Android開發(fā)經(jīng)驗談:并發(fā)編程(線程與線程池)(推薦)
- Android中Retrofit的簡要介紹
- android分享純圖片到QQ空間實現(xiàn)方式
- Android權(quán)限如何禁止以及友好提示用戶開通必要權(quán)限詳解
- 史上最全Android build.gradle配置詳解(小結(jié))
- Android中再按一次退出提醒實現(xiàn)的兩種方法
相關(guān)文章
Android自定義控件(實現(xiàn)視圖樹繪制指示器)
本文主要介紹了Android視圖樹繪制指示器的實現(xiàn)原理和具體步驟。具有一定的參考價值,下面跟著小編一起來看下吧2017-01-01
Android利用FlexboxLayout輕松實現(xiàn)流動布局
flexbox是屬于CSS的一種布局方案,可以簡單、完整、響應(yīng)式的實現(xiàn)各種頁面布局。谷歌將其引入以提高復(fù)雜布局的能力。下面這篇文章主要給大家介紹了在Android中利用FlexboxLayout輕松實現(xiàn)流動布局的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-04-04
Android自定義View繪制貝塞爾曲線實現(xiàn)流程
貝塞爾曲線的本質(zhì)是通過數(shù)學(xué)計算的公式來繪制平滑的曲線,分為一階,二階,三階及多階。但是這里不講數(shù)學(xué)公式和驗證,那些偉大的數(shù)學(xué)家已經(jīng)證明過了,所以就只講講Android開發(fā)中的運用吧2022-11-11
Activity透明/半透明效果的設(shè)置transparent(兩種實現(xiàn)方法)
兩種方法實現(xiàn)Activity透明/半透明效果的設(shè)置,代碼思路很有調(diào)理,感興趣的朋友可以參考下,希望本文可以幫助到你2013-02-02
Android學(xué)習(xí)之Intent中顯示意圖和隱式意圖的用法實例分析
這篇文章主要介紹了Android學(xué)習(xí)之Intent中顯示意圖和隱式意圖的用法,以實例形式分析了Intent通訊的相關(guān)技巧與注意事項,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10
Android制作微信app頂部menu菜單(ActionBar)
這篇文章主要為大家詳細介紹了Android利用ActionBar制作微信app頂部menu菜單,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02

