UI设计启动页的时候问,Android能够实现从里到外辐射的渐变色吗?我没有立即回答,因为我只知道线性渐变色,别的不清楚,捂脸。因此,立即百度一下,发现真的有,并且还有扇形渐变色,所以记录下来,备忘。
百度后,发现渐变色不仅可以根据xml来实现,也可以用java代码来实现,由于目前没有那么多时间,只记录xml实现的方法;以后在记录Java实现的代码。
通过Shape gradient标签来实现
首先来看gradient标签所有的渐变属性:
<gradient
android:angle="integer"
android:centerX="integer"
android:centerY="integer"
android:centerColor="integer"
android:endColor="color"
android:gradientRadius="integer"
android:startColor="color"
android:type=["linear" | "radial" | "sweep"]
android:useLevel=["true" | "false"] />
attributes:
* android:angle
Integer,代表渐变颜色的角度, 0 is left to right, 90 is bottom to top. 必须是45的整数倍. 默认是 0.该属性只有在type=linear情况下起作用,默认的type为linear。
* android:startColor
Color. 颜色渐变的开始颜色
- android:endColor
Color. 颜色渐变的结束颜色
- android:centerColor
Color. 颜色渐变的中间颜色
- android:centerX
Float.(0 - 1.0) 相对X的渐变位置。
- android:centerY