[英]Set listView divider's width
我试图将listView与分隔符一起使用,而我正要更改分隔符的宽度,所以我在网站上查找了以下解决方案:
在我的应用中进行测试时,我没有分隔线,但是如果我切换为使用简单的颜色,分隔线会再次出现
这是我的代码:
我的活动布局:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="80sp"
android:elegantTextHeight="true"
android:text="Paramètres"
android:textSize="24sp"
android:gravity="center"
android:textColor="#ffffff"
android:background="#191919"/>
<ListView
android:id="@+id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:dividerHeight="2dp"
android:divider="@drawable/list_divider">
</ListView>
</LinearLayout>
list_divider.xml
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="15dp"
android:insetRight="15dp" >
<shape
android:shape="rectangle" >
<stroke
android:dashGap="1dp"
android:dashWidth="1.5dip"
android:width="2dp"
android:color="#000000" />
<size android:height="3dp"/>
</shape>
</inset>
您为分频器属性指定了错误的文件名。更改此行
android:divider="@drawable/list_devider"
至
android:divider="@drawable/list_divider"
因为您的列表分隔符可绘制文件名为list_divider
而不是list_devider
我建议您将px
用作dividerHeight
而不是dp
如果您指定1dp或1dip,Android将按比例缩小。 在120dpi的设备上,转换后的像素变为0.75px,四舍五入为0。在某些设备上,转换为2-3像素,通常看起来很丑或草率。
对于分隔线,如果要使用1像素分隔线,则1px是正确的高度,并且是“一切都应浸入”规则的例外之一。 在所有屏幕上均为1像素。 此外,在hdpi及以上屏幕上,通常1px的效果更好
所以我修改了我的listdivide.xml文件,它起作用了:
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="16dp"
android:insetRight="16dp">
<shape>
<solid android:color="#000000" />
<corners android:radius="1dp" />
</shape>
</inset>
但是我仍然不知道为什么第一个不起作用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.