赞
踩
先举个例子:
如图:三种颜色从左往右渐变
以下为各个属性详解:
1.angle
android:angle=“Integer” :当android:type=“linear” 时,angle为渐变的角度:0 代表从左往右渐变,90 从上到下,180从右往左,360左往右。
值为 0 到 360,必须是45的倍数或0。(ps:type不等于linear时是不起作用的)
2.startColor、centerColor、endColor
android:startColor=“color” :渐变开始位置的颜色,值为16色类型,例:#448AFF 。
android:centerColor=“color” :渐变中间位置的颜色
android:endColor=“color” 渐变结束位置的颜色
(ps:当android:type="linear"时,android:centerX="Integer"或android:centerY=“Integer” 可以更改中间颜色的位置)
3.type
android:type=""
3.1:值为linear时,线性渐变:上面已讲;
3.2:值为:sweep:扫描渐变,也就是从右旋转一圈渐变,起始位置默认中间(就是中间三个颜色交点那),例:
加入这两个属性,可以更改起始位置,根据X、Y的值确定起始位置。其值为 0 到 1
android:centerX=“0.5”
android:centerY=“0.8”
3.3:值为radial时:径向渐变,必须配合 android:gradientRadius=""(圆形渐变的大小,值可以为纯数字或 sp 等等) 使用,例:
加入这两个属性,可以更改起始位置,根据X、Y的值确定起始位置。其值为 0 到 1
android:centerX=“0.5”
android:centerY=“0.8”
举例图,圆形渐变:
代码:
<?xml version="1.0" encoding="utf-8"?><!--
android:shape="oval":画圆
size 标签:圆的宽高
-->
<size
android:width="120dp"
android:height="120dp"/>
<gradient
android:type="linear"
android:angle="0"
android:startColor="#448AFF"
android:centerColor="@color/colorWhite"
android:endColor="#69F0AE"/>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。