InsetDrawable

来源:互联网 发布:simulink一端口多输入 编辑:程序博客网 时间:2024/05/17 17:44
public class

InsetDrawable

extends DrawableWrapper
java.lang.Object   ↳android.graphics.drawable.Drawable    ↳android.graphics.drawable.DrawableWrapper     ↳android.graphics.drawable.InsetDrawable



 InsetDrawable 表示一个drawable嵌入到另外一个drawable内部,并且在内部留一些间距,这一点很像drawable的padding属性,
区别在于 padding表示drawable的内容与drawable本身的边距,insetDrawable表示两个drawable和容器之间的边距。当控件需要
的背景比实际的边框小的时候比较适合使用InsetDrawable。

在xml文件中使用inset作为跟节点定义InsetDrawable。

android:inset  API21才有的属性android:insetTop:图像距离上边的距离。android:insetRight:图像距离右侧的距离。android:insetBottom:图像距离底边的距离。android:insetLeft:图像距离左侧的距离。

<?xml version="1.0" encoding="utf-8"?><inset xmlns:android="http://schemas.android.com/apk/res/android"    android:insetBottom="50dp"    android:insetLeft="50dp"    android:insetRight="50dp"    android:insetTop="50dp" >    <bitmap        android:antialias="true"        android:autoMirrored="true"        android:dither="true"        android:filter="true"        android:gravity="center"        android:mipMap="true"        android:src="@drawable/ic_launcher"        android:tileMode="repeat" >    </bitmap></inset>

或者
<?xml version="1.0" encoding="utf-8"?><inset xmlns:android="http://schemas.android.com/apk/res/android"   android:drawable="@drawable/bitmap"   android:insetLeft="50dp"   android:insetRight="50dp"   android:insetTop="50dp"   android:insetBottom="50dp"    ></inset>


设置背景
 android:background="@drawable/inset_drawable"
或者
Drawable background  = getResources().getDrawable(R.drawable.inset_drawable);if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){imageView.setBackground(background);}else{imageView.setBackgroundDrawable(background);}









0 0
原创粉丝点击