第二篇了,今天朋友问怎么代码实现渐变。当时感觉之前应该是写过,翻了一下,果然。进入正题。
看图
三种颜色: 绿色, 红色, 橙色
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#f28e00"
android:centerColor="#f21d00"
android:endColor="#8fc41f" android:angle="180.0" />
<corners
android:topLeftRadius="8dip"
android:bottomLeftRadius="8dip"/>
</shape>
corners 圆角属性,可以直接忽略。
gradient : 用到了四个属性 ,startColor 起始颜色, centerColor 中间颜色, endColor 结尾颜色 ,颜色值可以根据需要更改, angle
180 水平排布, 如果你写90 会变成垂直排布, 我没看过源码,不清楚原理, 都是试出来的。
声明:我没有看到网上有类似文章,而且本文介绍的也属于android基础内容,不存在版权问题。如有雷同文章纯属巧合。