Android Drawable Resources系列3:

定义:图层数组,根据先后顺序,越往后,图层越在顶部。

A LayerDrawable is a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top.

FILE LOCATION:
res/drawable/filename.xml
The filename is used as the resource ID.
RESOURCE REFERENCE:
In Java: R.drawable.filename
In XML: @[package:]drawable/filename

SYNTAX:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@[package:]drawable/drawable_resource"
        android:id="@[+][package:]id/resource_name"
        android:top="dimension"
        android:right="dimension"
        android:bottom="dimension"
        android:left="dimension" />
</layer-list>

参数名 作用
item

可以直接使用drawable资源,也可以使用<bitmap>、<selector>标签的资源

<item android:drawable="@drawable/image" />

<item>
  <bitmap android:src="@drawable/image"
          android:gravity="center" />
</item>


top、right、bottom、left 距离顶部、右边、底部、左边的距离。


效果示例:

资源:res\drawable\resource_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="@drawable/resource_drawable_bitmap" />
    <item android:top="40dp" android:left="40dp">
        <bitmap android:src="@mipmap/reasource_drawable_mn" />
    </item>
    <item android:top="80dp" android:left="80dp">
        <bitmap android:src="@mipmap/reasource_drawable_mn" />
    </item>
</layer-list>

使用:

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:src="@drawable/resource_drawable_layer_list" />

效果:

Android Drawable Resources系列3:<layer-list>_第1张图片


你可能感兴趣的:(Android Drawable Resources系列3:)