Android-layer List
You can use Layer-list to cascade multiple drawable together in order.
1. We can achieve results through layer-list and selector
The graph is implemented by using a red background layer and a white background layer, and the white background layer is shifted upward by setting the android:bottom
red background layer at the bottom of the graph. The Offset property is actually Margin
a function.
Code:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true"> <layer-list> <item android:drawable="@android:color/holo_red_dark" /> <item android:bottom="4dp" android:drawable="@android:color/white" /> </layer-list> </item> <item android:state_checked="false"> <layer-list> <item android:drawable="@android:color/holo_red_dark" /> <item android:bottom="2dp" android:drawable="@android:color/white" /> </layer-list> </item></selector>
2. Achieve Shadow Effect
Offset refers to moving the entire layer
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 灰色阴影 --> <item android:left="2dp" android:top="4dp"> <shape> <solid android:color="@android:color/darker_gray" /> <corners android:radius="10dp" /> </shape> </item> <!-- 白色前景 --> <item android:bottom="4dp" android:right="2dp"> <shape> <solid android:color="#FFFFFF" /> <corners android:radius="10dp" /> </shape> </item></layer-list>
Learning from: Keegan Steel (http://keeganlee.me/post/android/20150909)
Android-layer List