Android Drawable - layer-list
LayerDrawable 是管理其他可绘制对象阵列的可绘制对象。列表中的每个可绘制对象均按照列表顺序绘制,列表中的最后一个可绘制对象绘于顶部。
每个可绘制对象由单一<layer-list>
元素内的<item>
元素表示。
文件位置:res/drawable/filename.xml 文件名用作资源 ID。
编译资源的数据类型: 指向 LayerDrawable 的资源指针。
资源引用:
- 在 Java 中:
R.drawable.filename
- 在 XML 中:
@[package:]drawable/filename
一些应用
1.显示border
参考:
实现left、top、right、bottom边界,如左边界(其它形式类推):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-2dp" android:bottom="-2dp" android:right="-2dp">
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#000"/>
</shape>
</item>
</layer-list
全边界如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">