Android中的Drawable资源—— InsetDrawable

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标签对应的是一个图片资源,在它里面,我们可以根据需要嵌入其他的图片资源,并且还指定了边距。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值