参考官方文档:
Inset Drawable

A drawable defined in XML that insets another drawable by a specified distance. This is useful when a View needs a background that is smaller than the View’s actual bounds.

意思是说,一个用xml定义的drawable,这个drawable嵌入到另外一个drawable内部并在内部留一些间距。这在View需要的背景比实际的边框小时候特别有用。有点像drawable的padding属性,区别在于 padding表示drawable的内容与drawable本身的边距,insetDrawable表示两个drawable和容器之间的边距。

概述

文件位置:

res/drawable/filename.xml
The filename is used as the resource ID.

资源引用:

res/drawable/filename.xml
The filename is used as the resource ID.

语法:

<?xml version="1.0" encoding="utf-8"?><inset  xmlns:android="http://schemas.android.com/apk/res/android" <!--Drawable 资源,引用一个drawable资源-->    android:drawable="@drawable/drawable_resource"     <!--与顶部的距离。可以使一个尺寸值,或者一个尺寸的资源。-->    android:insetTop="dimension"    android:insetRight="dimension"    android:insetBottom="dimension"    android:insetLeft="dimension" />

使用

比如我们的ListView 的divider 需要设置离屏幕两边 的距离的时候,可以使用Inset Drawable

divider.xml

<?xml version="1.0" encoding="utf-8"?><inset xmlns:android="http://schemas.android.com/apk/res/android" android:insetLeft="10dp" android:insetRight="10dp">    <shape android:shape="rectangle">        <solid android:color="@color/color_line" />    </shape></inset>
<ListView  android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/white" android:id="@android:id/list" android:dividerHeight="1dp" android:divider="@drawable/divider"/>

更多相关文章

  1. Android在onCreate()中获得控件尺寸
  2. API 25 (Android(安卓)7.1.1 API) widget.ImageView——属性分析
  3. android开发资源
  4. Android(安卓)API 中文(14) —— ViewStub
  5. Android(安卓)入门到精通 (界面编程#2-Menu)
  6. android 读取资源字符串的 方法
  7. Android中调用Rest web服务
  8. Android开发便签9:在android资源文件中定义字符串数组
  9. Android(安卓)frameworks添加资源后编译报错:找不到添加的内部资

随机推荐

  1. Android(安卓)完美解决各个版本状态栏设
  2. Android 控件布局实现卡片效果,阴影效果
  3. android中调用App市场对自身App评分
  4. Android无法访问本地服务器(localhost)的解
  5. 给 Android 开发工程师的一份面试指南,包
  6. Android telephone
  7. android 聊天用RecyclerView获取键盘高度
  8. android离线安装
  9. Android 中ContentProvider的用法及用Con
  10. Android(安卓)WebView挂马漏洞--各大厂商