安卓shape渐变色的种类及处理方法

android 颜色渐变是指通知xml或者java代码,设置相关参数,是界面的某个指定的视图显示成从开始位置的颜色,逐渐过度到结尾位置的颜色的技术。

android颜色渐变的分类有:

LinearGradient线性渐变

RadialGradient镜像渐变

 SweepGradient角度渐变

一、LinearGradient线性渐变顾名思义,是只颜色在一个直线方向上逐渐改变。

文件代码:

1
2
3
4
5
6
7
8
9
10
<?xml version= "1.0"  encoding= "utf-8" ?>
<shape xmlns:android= "http://schemas.android.com/apk/res/android"
     android:shape= "oval"  >
 
     <gradient
         android:endColor= "#0000FF"
         android:startColor= "#FF0000"
         android:type= "linear"  />
 
</shape>

效果:

二、RadialGradient镜像渐变镜像渐变就是楼主问的问题了:只要将type设置为oval,然后增加

        android:gradientRadius

属性。

楼主特殊要求是圆形的话,需要在shape里面添加android:shape="oval"

文件代码:

1
2
3
4
5
6
7
8
9
10
11
<?xml version= "1.0"  encoding= "utf-8" ?>
<shape xmlns:android= "http://schemas.android.com/apk/res/android"
     android:shape= "oval"  >
 
     <gradient
         android:endColor= "#0000FF"
         android:gradientRadius= "100%p"
         android:startColor= "#FF0000"
         android:type= "linear"  />
 
</shape>

效果:

三、 SweepGradient角度渐变

是指以中心点为射线的一个断点,顺时针旋转所扫过的区域,颜色逐渐改变的一种渐变方式

1
2
3
4
5
6
7
8
9
<?xml version= "1.0"  encoding= "utf-8" ?>
<shape xmlns:android= "http://schemas.android.com/apk/res/android"  >
 
     <gradient
         android:endColor= "#0000FF"
         android:startColor= "#FF0000"
         android:type= "sweep"  />
 
</shape>

效果图:

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值