android inset 标签,Drawable子类之——InsetDrawable (嵌入)

本文出自 “阿敏其人” 简书博客,转载或引用请注明出处。

InsetDrawable对应的标签是

他可以将其他的Drawable内嵌到自己的里面。个人觉得其实没什么用,他能做到的,LayerDrawable也能做,或者有的时候直接设置一下padding就可以了。

一、语法

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" />

没什么好说的,四个方向就是想要拉开的距离,比如一个图片本来应该是占满屏幕的,然后上下左右个设置为20dp,那么待会这个图片就不会占满屏幕,就是距离上下左右都有20dp的距离。

二、demo

insetdrawable_simple.xml

android:insetBottom="60dp"

android:insetLeft="30dp"

android:insetRight="30dp"

android:insetTop="60dp" >

.

.

布局文件

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

android:id="@+id/mIv"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_centerInParent="true"

android:background="@mipmap/op"

android:src="@drawable/insetdrawable_simple"

/>

.

.

Activity代码什么都不要动

import android.app.Activity;

import android.os.Bundle;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

//InsetDrawable insetDrawable=new InsetDrawable(getResources().getDrawable(R.drawable.XXX), 20, 30, 30, 20);

}

}

.

.

demo效果:

b1c2d2d3dfb5

demo效果.png

了解更多的Drawable分类 Drawable图像资源抽象类

本篇完。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值