转载drawable中的shape,看文档过程中gradient属性不是很理解。本着站在巨人肩膀上学习的态度,上网找资料。估计打开方式不对,找到资料甚少,只能自己动手,当做笔记,有错请指正,谢谢~
首先文档介绍:shape的颜色渐变属性
<gradient>attributes:
- Integer,代表渐变颜色的角度, 0 is left to right, 90 is bottom to top. 必须是45的整数倍.
- 默认是 0.该属性只有在type=linear情况下起作用,默认的type为linear。
默认情况下,从左到右:
- xml代码:<gradient
android:startColor="#000000"
android:endColor="#ffffff"
/>

angle=270,从上到下 :

- xml代码:<gradient
android:startColor="#000000"
android:endColor="#ffffff"
android:angle="270"
/>
- Color. 颜色渐变的开始颜色,如angle=270中的 android:startColor="#000000"
- Color. 颜色渐变的结束颜色,如angle=270中的 android:endColor="#ffffff"
- Color. 颜色渐变的中间颜色,主要用于多彩。
-

-
<gradient
android:startColor="#000000"
android:endColor="#ffffff"
android:centerColor="#ff0000"
/>
- Float.(0 - 1.0) 相对X的渐变位置。
- Float.(0 - 1.0) 相对Y的渐变位置。
- 这两个属性只有在type不为linear情况下起作用。
-
Float. 渐变颜色的半径,单位应该是像素点. 需要
android:type="radial".
如果android:type="radial",没有设置android:gradientRadius,将会报错,error
inflating class.
-
Value Description "linear"线性渐变.可以理解为 y=kx+b. "radial"A radial gradient.圆形渐变,起始颜色从cenralX,centralY点开始。 "sweep"A sweeping line gradient.
android:angleandroid:startColorandroid:endColorandroid:centerColorandroid:centerXandroid:centerYandroid:gradientRadius
xml代码: <gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="30"
android:type="radial"
/>
加入android:centerColor属性

<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerColor="#000000"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="30"
android:type="radial"
/>
android:type
centerX="0.2" centerX="0.2" 

android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.2"
android:centerX="0.2"
android:gradientRadius="30"
android:type="radial"
/> type="sweep":


xml代码:
<gradientandroid:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.5"
android:centerY="0.5"
android:type="sweep"
/>
本文详细解析了Android中Drawable的Gradient属性,包括角度设置、颜色变化、类型选择等内容,并通过实例展示了不同属性组合的效果。
3013

被折叠的 条评论
为什么被折叠?



