今天做一个列表发现有两条长短不一的线,一开始在listview设置了一条在在item设置了一条,发现两条线会重叠。。。。。。
后来想能不能直接设置divider的边距,上网查下还真有,
参考了国外的方法解决了divider边距和item边距需要设置不同长短的问题。
主要就是使用了insetdrawable,当控件需要的背景比实际的边框小的时候比较适合使用InsetDrawable。
drawable/list_line_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/cut_off_rule_line" />
</shape>
</inset>
listview使用
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bgcolor"
android:cacheColorHint="#00000000"
android:divider="@drawable/list_line_divider"
android:dividerHeight="1px" />