android_基础_shape的gradient属性详解

121 篇文章 1 订阅

转载自: https://blog.csdn.net/zjdyhant/article/details/46537647

首先文档介绍:

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

<gradient>

shape的颜色渐变属性

attributes:

android:angle

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"  
        />  

android:startColor

Color. 颜色渐变的开始颜色,如angle=270中的 android:startColor="#000000"

android:endColor

Color. 颜色渐变的结束颜色,如angle=270中的 android:endColor="#ffffff"

android:centerColor

Color. 颜色渐变的中间颜色,主要用于多彩。

<gradient   
        android:startColor="#000000"  
        android:endColor="#ffffff"  
        android:centerColor="#ff0000"  
        />  

android:centerX

Float.(0 - 1.0) 相对X的渐变位置。

android:centerY

Float.(0 - 1.0) 相对Y的渐变位置。

这两个属性只有在type不为linear情况下起作用。

android:gradientRadius

Float. 渐变颜色的半径,单位应该是像素点. 需要 android:type="radial".

如果android:type="radial",没有设置android:gradientRadius,将会报错,error inflating class.                       ![](https://img-blog.csdnimg.cn/img_convert/2ec6784c94e479a4b2671baf59088a72.png)                

xml代码:

加入android:centerColor属性

 ![](https://img-blog.csdnimg.cn/img_convert/754dd103eeefeb4ca2fb9a3471e8910a.png)      


android:type

Value

Description

"linear"

线性渐变.可以理解为 y=kx+b.

"radial"

A radial gradient.圆形渐变,起始颜色从cenralX,centralY点开始。

"sweep"

A sweeping line gradient.

centerX=“0.2” centerX=“0.2”

xml代码: type=“sweep”:

xml代码:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值