Drawable & layer-list 实现渐变色+单色组合

2018-06-11  本文已影响0人  南窗云

遇到要用渐变色+单色组合的背景,需要用到 layer-list 实现:


渐变色+单色组合的背景

实现思路

  1. 用白色做底色
  2. 下面的item会覆盖掉上面的,用渐变色
  3. 设置 android:bottom="28dp" 偏移,就会露出底色

代码

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/color_ffffff" />
        </shape>
    </item>
    <item android:bottom="28dp">
        <shape android:shape="rectangle">
            <gradient
                android:angle="270"
                android:endColor="#FFC795"
                android:startColor="#FF922C" />
        </shape>
    </item>
</layer-list>
上一篇下一篇

猜你喜欢

热点阅读