android 渐变drawable

渐变Drawable是使用<gradient>标记作为形状Drawable定义中的子节点定义的。

每个渐变Drawable都要求至少要有一个startColor和endColor属性,并且支持一个可选的middleColor属性。通过使用type属性,可以把渐变定义为以下的某种类型:

线性:这是默认的渐变类型,它显示了按照angle属性定义的角度从startColor到endColor的直接颜色过渡。

辐射:从形状的外边界到中心绘制从startColor到endColor的圆形渐变。

扫描:绘制一个扫描渐变,它将沿着父形状(通常是一个圆环)的外边界从startColor到endColor进行过渡。

1.在res下新建drawable文件夹。

2.在drawable文件夹下新建xml文件。

3.在组件的bacground属性里引用此文件。

下面是线性的代码和效果:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"
    android:useLevel="false"
    >
    <gradient 
        android:startColor="#ffffff"
        android:endColor="#ffffff"
        android:centerColor="#000000"
        android:useLevel="false"
        android:type="linear"
        android:angle="45"
        />
</shape>



辐射渐变的椭圆

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval"
    android:useLevel="false"
    >
    <gradient 
        android:type="radial"
        android:startColor="#ffffff"
        android:endColor="#ffffff"
        android:centerColor="#000000"
        android:useLevel="false"
        android:gradientRadius="300"
        />

</shape>



扫描渐变:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="ring"
    android:useLevel="false"
    android:innerRadiusRatio="3"
    android:thicknessRatio="8"
    >
    <gradient 
        android:startColor="#ffffff"
        android:endColor="#ffffff"
        android:centerColor="#000000"
        android:useLevel="false"
        android:type="sweep"
        />
    

</shape>
<!-- 扫描渐变的椭圆 -->


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值