android 渐变drawable
漸變Drawable它是使用<gradient>的標記的形狀Drawable定義子節點的定義。
每個梯度Drawable求至少要有一個startColor和endColor屬性,而且支持一個可選的middleColor屬性。
通過使用type屬性,能夠把漸變定義為下面的某種類型:
線性:這是默認的漸變類型,它顯示了依照angle屬性定義的角度從startColor到endColor的直接顏色過渡。
輻射:從形狀的外邊界到中心繪制從startColor到endColor的圓形漸變。
掃描:繪制一個掃描漸變,它將沿著父形狀(一般是一個圓環)的外邊界從startColor到endColor進行過渡。
1.在res下新建drawable目錄。
2.在drawable目錄下新建xml文件。
3.在組件的bacground屬性里引用此文件。
以下是線性的代碼和效果:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:useLevel="false"
>
<gradient
android:startColor="#ffffff"
android:endColor="#ffffff"
android:centerColor="#000000"
android:useLevel="false"
android:type="linear"
android:angle="45"
/>
</shape>
輻射漸變的橢圓
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" android:useLevel="false" > <gradient android:type="radial" android:startColor="#ffffff" android:endColor="#ffffff" android:centerColor="#000000" android:useLevel="false" android:gradientRadius="300" /> </shape>
掃描漸變:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:useLevel="false"
android:innerRadiusRatio="3"
android:thicknessRatio="8"
>
<gradient
android:startColor="#ffffff"
android:endColor="#ffffff"
android:centerColor="#000000"
android:useLevel="false"
android:type="sweep"
/>
</shape>
<!-- 掃描漸變的橢圓 -->
<img src="http://img.blog.csdn.net/20140809160015126?
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaG93bGFh/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
版權聲明:本文博客原創文章,博客,未經同意,不得轉載。
總結
以上是生活随笔為你收集整理的android 渐变drawable的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 除了 Apple Music、网易云音乐
- 下一篇: 多点app怎么绑定美通卡(汉典多字的基本