Android實(shí)現(xiàn) Shape屬性gradient 漸變效果
1,gradient(漸變)
【1】<gradient>用以定義漸變色,可以定義兩色漸變和三色漸變,及漸變樣式;
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:type=["linear" | "radial" | "sweep"] //共有3中漸變類型,線性漸變(默認(rèn))/放射漸變/掃描式漸變 android:angle="integer" //漸變角度,必須為45的倍數(shù),0為從左到右,90為從上到下 android:centerX="float" //漸變中心X的相當(dāng)位置,范圍為0~1 android:centerY="float" //漸變中心Y的相當(dāng)位置,范圍為0~1 android:startColor="color" //漸變開始點(diǎn)的顏色 android:centerColor="color" //漸變中間點(diǎn)的顏色,在開始與結(jié)束點(diǎn)之間 android:endColor="color" //漸變結(jié)束點(diǎn)的顏色 android:gradientRadius="float" //漸變的半徑,只有當(dāng)漸變類型為radial時才能使用 android:useLevel=["true" | "false"] /> //使用LevelListDrawable時就要設(shè)置為true。設(shè)為false時才有漸變效果
首先有三種漸變類型,分別是:linear(線性漸變)、radial(放射性漸變)、sweep(掃描式漸變)
</shape>
- android:useLevel屬性通常不使用。該屬性用于指定是否將該shape當(dāng)成一個LevelListDrawable來使用,默認(rèn)值為false。
- angle屬性確實(shí)只對線性漸變有效,其它兩種漸變方式都沒有任何動靜
- centerX、centerY兩個屬性用于設(shè)置漸變的中心點(diǎn)位置,僅當(dāng)漸變類型為放射漸變時有效。
2,Demo實(shí)現(xiàn)效果
- 我們使用三色漸變來看看這三種漸變方式都是怎么顯示的:(如果不使用centerColor屬性就是雙色漸變,這個屬性是可選的)
- 注意: 在構(gòu)造放射性漸變時,要加上android:gradientRadius屬性(漸變半徑),即必須指定漸變半徑的大小才會起作用
【1】 線性漸變
實(shí)現(xiàn)效果
shape 代碼
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:type="linear" android:startColor="#ff0000" android:centerColor="#00ff00" android:endColor="#0000ff"/> </shape>
【2】 放射性漸變
實(shí)現(xiàn)效果
實(shí)現(xiàn)代碼
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:type="radial" android:startColor="#ff0000" android:centerColor="#00ff00" android:endColor="#0000ff" android:gradientRadius="100"/> </shape>
【3】 掃描式漸變
實(shí)現(xiàn)效果
實(shí)現(xiàn)代碼
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:type="sweep" android:startColor="#ff0000" android:centerColor="#00ff00" android:endColor="#0000ff"/> </shape>
【4】android:angle屬性修改漸變角度 (僅對線性漸變有效)
1)android:angle="integer" //漸變角度,必須為45的倍數(shù),0為從左到右,90為從上到下
2)angle屬性確實(shí)只對線性漸變有效,其它兩種漸變方式都沒有任何動靜
實(shí)現(xiàn)效果:
實(shí)現(xiàn)代碼:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:type="linear" android:startColor="#ff0000" android:centerColor="#00ff00" android:endColor="#0000ff" android:angle="45"/> </shape>
【5】android:centerX與android:centerY
1) android:centerX="0.2",android:centerY="0.8"
2)centerX、centerY兩個屬性用于設(shè)置漸變的中心點(diǎn)位置,僅當(dāng)漸變類型為放射漸變時有效。
3)類型為分?jǐn)?shù)或小數(shù),不接受Dimension。默認(rèn)值是0.5,有效值是0.0~1.0,超出該范圍后會看不出漸變效果。centerX、centerY的取值其實(shí)是寬和高的百分比
實(shí)現(xiàn)效果
實(shí)現(xiàn)代碼: 取寬度的20%和高度的80%的位置,作為新的漸變原點(diǎn)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:type="sweep" android:startColor="#ff0000" android:centerColor="#00ff00" android:endColor="#0000ff" android:centerX="0.2" android:centerY="0.8"/> </shape>
總結(jié)
以上所述是小編給大家介紹的Android實(shí)現(xiàn) Shape屬性gradient 漸變效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
Android自定義ViewPagerIndicator實(shí)現(xiàn)炫酷導(dǎo)航欄指示器(ViewPager+Fragment)
這篇文章主要為大家詳細(xì)介紹了Android自定義ViewPagerIndicator實(shí)現(xiàn)炫酷導(dǎo)航欄指示器,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02android實(shí)現(xiàn)raw文件夾導(dǎo)入數(shù)據(jù)庫代碼
這篇文章主要介紹了android實(shí)現(xiàn)raw文件夾導(dǎo)入數(shù)據(jù)庫代碼,有需要的朋友可以參考一下2013-12-12RxJava和Retrofit2的統(tǒng)一處理單個請求示例詳解
這篇文章主要給大家介紹了關(guān)于RxJava和Retrofit2的統(tǒng)一處理單個請求的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11Flutter以兩種方式實(shí)現(xiàn)App主題切換的代碼
這篇文章主要介紹了Flutter以兩種方式實(shí)現(xiàn)App主題切換的代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04Android UI設(shè)計(jì)系列之自定義ViewGroup打造通用的關(guān)閉鍵盤小控件ImeObserverLayout(9)
這篇文章主要介紹了Android UI設(shè)計(jì)系列之自定義ViewGroup打造通用的關(guān)閉鍵盤小控件ImeObserverLayout,具有一定的實(shí)用性和參考價值,感興趣的小伙伴們可以參考一下2016-06-06Android自定義StickinessView粘性滑動效果
這篇文章主要為大家詳細(xì)介紹了Android自定義StickinessView粘性滑動效果的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03Android編程之短信竊聽器實(shí)現(xiàn)方法
這篇文章主要介紹了Android編程之短信竊聽器實(shí)現(xiàn)方法,以實(shí)例形式較為詳細(xì)的分析了Android編程實(shí)現(xiàn)竊聽器的具體步驟與實(shí)現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11Android調(diào)用系統(tǒng)時間格式顯示時間信息
這篇文章主要介紹了Android調(diào)用系統(tǒng)時間格式顯示時間信息的使用方法,代碼很簡單2014-01-01Flutter實(shí)現(xiàn)可循環(huán)輪播圖效果
這篇文章主要介紹了Flutter實(shí)現(xiàn)可循環(huán)輪播圖效果,本文圖文并茂通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2019-07-07