失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Android开发之渐变效果gradient属性

Android开发之渐变效果gradient属性

时间:2019-07-17 13:15:22

相关推荐

Android开发之渐变效果gradient属性

Android开发之渐变效果gradient属性

首先文档介绍:

<gradientandroid: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"] />

<gradient>shape的颜色渐变属性

attributes:

android:angleInteger,代表渐变颜色的角度,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"

/>

android:startColorColor. 颜色渐变的开始颜色,如angle=270中的android:startColor="#000000"android:endColorColor.颜色渐变的结束颜色,如angle=270中的android:endColor="#ffffff"android:centerColorColor.颜色渐变的中间颜色,主要用于多彩。

<gradient

android:startColor="#000000"

android:endColor="#ffffff"

android:centerColor="#ff0000"

/>

android:centerXFloat.(0 - 1.0)相对X的渐变位置。android:centerYFloat.(0 - 1.0)相对Y的渐变位置。 这两个属性只有在type不为linear情况下起作用。android:gradientRadiusFloat. 渐变颜色的半径,单位应该是像素点. 需要android:type="radial". 如果android:type="radial",没有设置android:gradientRadius,将会报错,error inflating class.

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"

xml代码:<gradient

android:startColor="#ff0000"

android:endColor="#ffffff"

android:centerX="0.2"

android:centerX="0.2"

android:gradientRadius="30"

android:type="radial"

/>type="sweep":

xml代码:

<gradient

android:startColor="#ff0000"

android:endColor="#ffffff"

android:centerX="0.5"

android:centerY="0.5"

android:type="sweep"

/>

如果觉得《Android开发之渐变效果gradient属性》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。