Android 设置listView分隔符';s宽度
我正在尝试使用带有分隔符的listView,我正要更改分隔符的宽度,所以我查看了网站,发现了以下解决方案: 当我在我的应用程序中测试时,我没有分频器,但是如果我切换到使用简单的颜色,分频器会再次出现 这是我的代码: 我的活动布局:Android 设置listView分隔符';s宽度,android,listview,width,divider,Android,Listview,Width,Divider,我正在尝试使用带有分隔符的listView,我正要更改分隔符的宽度,所以我查看了网站,发现了以下解决方案: 当我在我的应用程序中测试时,我没有分频器,但是如果我切换到使用简单的颜色,分频器会再次出现 这是我的代码: 我的活动布局: android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android
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>
android:layout\u width=“match\u parent”
android:layout\u height=“match\u parent”
android:orientation=“vertical”>
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"
到
因为您的列表分隔器可绘制文件名是list\u divider
而不是list\u devider
我建议您使用px
作为dividerHeight
而不是dp
如果您指定1dp或1dip,Android会将其缩小。在一台120dpi的设备上,这变成了类似于0.75px的转换值,即四舍五入为0。在某些设备上,这转换为2-3像素,通常看起来很丑或邋遢
对于除法器,如果您想要1像素的除法器,1px是正确的高度,并且是“一切都应该倾斜”规则的例外之一。在所有屏幕上都是1像素。另外,1px通常在hdpi和以上屏幕上看起来更好,所以我修改了我的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>
但是我仍然不知道为什么第一个不起作用:)谢谢你的帮助。我也看到了,我换了一个正确的名字,但风格不起作用:(你活动的背景色是什么?)我不选择任何背景颜色。它是白色的
<?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>