天天看點

Android layer-list(1)



Android layer-list(1)

Android layer-list,顧名思義,實作清單組合後形成的圖層,寫一個例子。

activity_main.xml檔案:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="zhangphil.demo.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="150dip"
        android:layout_centerInParent="true"
        android:background="@drawable/layer_list"
        android:text="zhang phil @csdn"
        android:gravity="center"
        android:textColor="@android:color/white"/>

</RelativeLayout>
           

其中TextView background需要的背景資源就是一個layer-list,位于drawable目錄下的layer_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@android:color/holo_red_light"></item>
    <item android:drawable="@mipmap/ic_launcher"></item>

</layer-list>           

注意layer-list裡面定義的item元素的先後順序,後者将直接覆寫在前者上面,一層一層覆寫。

代碼運作結果:

附錄文章:

1,《Android AnimationDrawable動畫與APP啟動引導頁面》連結位址:

http://blog.csdn.net/zhangphil/article/details/47416915

2,《Android ImageView的setImageLevel和level-list使用簡介》連結位址:

http://blog.csdn.net/zhangphil/article/details/48936209

繼續閱讀