且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android layer-list(1)

更新时间:2022-08-21 20:55:38



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元素的先后顺序,后者将直接覆盖在前者上面,一层一层覆盖。


代码运行结果:

Android layer-list(1)


附录文章:
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