InsetDrawable

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值