Android(安卓)Inset Drawable
16lz
2022-05-26
参考官方文档:
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"/>
更多相关文章
- Android在onCreate()中获得控件尺寸
- API 25 (Android(安卓)7.1.1 API) widget.ImageView——属性分析
- android开发资源
- Android(安卓)API 中文(14) —— ViewStub
- Android(安卓)入门到精通 (界面编程#2-Menu)
- android 读取资源字符串的 方法
- Android中调用Rest web服务
- Android开发便签9:在android资源文件中定义字符串数组
- Android(安卓)frameworks添加资源后编译报错:找不到添加的内部资