Android layer-list(1)

来源:互联网 发布:python 判断加载完成 编辑:程序博客网 时间:2024/06/08 19:11


Android layer-list(1)

Android layer-list,顾名思义,实现列表组合后形成的图层,写一个例子。
activity_main.xml文件:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     tools:context="zhangphil.demo.MainActivity">  
  7.   
  8.     <TextView  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="150dip"  
  11.         android:layout_centerInParent="true"  
  12.         android:background="@drawable/layer_list"  
  13.         android:text="zhang phil @csdn"  
  14.         android:gravity="center"  
  15.         android:textColor="@android:color/white"/>  
  16.   
  17. </RelativeLayout>  


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

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">  
  3.   
  4.     <item android:drawable="@android:color/holo_red_light"></item>  
  5.     <item android:drawable="@mipmap/ic_launcher"></item>  
  6.   
  7. </layer-list>  
注意layer-list里面定义的item元素的先后顺序,后者将直接覆盖在前者上面,一层一层覆盖。


代码运行结果:

0 0
原创粉丝点击