渐变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=””>
版权声明:本文博客原创文章,博客,未经同意,不得转载。
最新评论