android 分割线,Android LinearLayout 分割线

本文详细介绍了如何在Android中自定义和使用divider,包括`android:divider`、`android:showDividers`和`android:dividerPadding`等属性的解析,以及如何通过InsetDrawable为divider添加内边距。示例代码展示了如何创建垂直方向的分隔线,并设置了显示在中间的位置。
摘要由CSDN通过智能技术生成

原生 divider

android:divider="?android:dividerHorizontal"

/>

自定义 divider

showDividers是分隔线的显示位置,beginning、middle、end分别代表显示在开始位置,中间,末尾。

android:id="@+id/km_calllog_root_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@android:color/white"

android:divider="@drawable/km_calllog_divider"

android:orientation="vertical"

android:showDividers="middle"/>

还有dividerPadding属性这里没有用到,意思很明确给divider添加padding。

android:shape="rectangle">

android:height="1dp"/>

设置一边距离的padding

android:insetLeft="20dp">

android:shape="rectangle">

android:width="1dp"

android:height="1dp"/>

InsetDrawable

定义这个drawable为InsetDrawable,必须作为根节点。

属性:xmlns:android

String类型。必须的,定义XML文件的命名空间,必须是 "http://schemas.android.com/apk/res/android".

android:drawable

Drawable 资源 。必须的。引用一个drawable资源

android:insetTop

尺寸。与顶部的距离。可以使一个尺寸值,或者一个尺寸的资源。

android:insetRight

尺寸。与右边的距离。可以使一个尺寸值,或者一个尺寸的资源。

android:insetBottom

尺寸。与底部的距离。可以使一个尺寸值,或者一个尺寸的资源。

android:insetLeft

尺寸。与左边的距离。可以使一个尺寸值,或者一个尺寸的资源。

示例

android:drawable="@drawable/background"

android:insetTop="10dp"

android:insetLeft="10dp" />

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值