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>
<!-- 扫描渐变的椭圆 -->


版权声明:本文博客原创文章,博客,未经同意,不得转载。






本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4688392.html,如需转载请自行联系原作者


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值