Android-layer List

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.