- 将多个图片或 shape 按照顺序层叠起来。
- 每个 item 标签里设置
android:top
android:bottom
android:left
android:right
表示 item 的上下左右间隔。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/layer_list1"/>
</item>
<item android:top="40dp" android:left="40dp">
<bitmap android:src="@drawable/layer_list2"/>
</item>
<item android:top="60dp" android:left="60dp">
<bitmap android:src="@drawable/layer_list3"/>
</item>
</layer-list>
组合使用:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item android:left="2dp" android:top="2dp">
<shape>
<gradient
android:startColor="#484848"
android:endColor="#7e7e7e"
android:centerColor="#484848"
android:centerY="0.9"
android:angle="270"/>
</shape>
</item>
<item android:bottom="2dp" android:right="2dp">
<shape>
<gradient
android:startColor="#524bb3"
android:endColor="#f5f5f5"
android:angle="45"
android:type="linear"/>
<padding
android:top="10dp"
android:bottom="10dp"
android:left="10dp"
android:right="10dp"/>
</shape>
</item>
</layer-list>
</item>
<item android:state_pressed="false">
<layer-list>
<item android:left="2dp" android:top="2dp">
<shape>
<gradient
android:startColor="#484848"
android:endColor="#7e7e7e"
android:angle="270"
android:centerColor="#484848"
android:centerY="0.9"/>
</shape>
</item>
<item android:bottom="2dp" android:right="2dp">
<shape>
<solid
android:color="#bc6767"/>
<stroke
android:width="2dp"
android:color="#121212"
android:dashWidth="10dp"
android:dashGap="5dp"/>
<corners
android:radius="20dp"
android:topLeftRadius="30dp"
android:topRightRadius="40dp"
android:bottomLeftRadius="50dp"
android:bottomRightRadius="60dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>