InsetDrawable 表示一个drawable嵌入到另外一个drawable内部,并且在内部留一些间距
存放位置:res/drawable/
使用方式:
在Java文件中:R.drawable.filename
在xml布局文件中:@[package:]drawable/filename
语法:
<?xml version="1.0" encoding="utf-8"?>
<inset
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/drawable_resource"
android:insetTop="dimension"
android:insetRight="dimension"
android:insetBottom="dimension"
android:insetLeft="dimension" />
这个xml实质会被解析为InsetDrawable对象,所以我们可以使用代码处理。
例如:
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/drawable_resource"
android:insetBottom="60dp"
android:insetLeft="30dp"
android:insetRight="30dp"
android:insetTop="60dp" >
<!--要插入的一个蓝色的矩形-->
<shape android:shape="rectangle" >
<solid android:color="#0000ff" />
</shape>
</inset>
上面可以看到inset标签对应的是一个图片资源,在它里面,我们可以根据需要嵌入其他的图片资源,并且还指定了边距。