【问题标题】:Set listView divider's width设置 listView 分隔线的宽度
【发布时间】:2015-12-09 14:55:51
【问题描述】:

我正在尝试使用带有分隔线的 listView 并且我正要更改分隔线的宽度,所以我查看了网站并找到了这个解决方案:

Listview divider margin

当我在我的应用中测试时,我没有分隔线,但如果我切换到使用简单的颜色,分隔线会再次出现

这是我的代码:

我的活动布局:

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 listview width divider


    【解决方案1】:

    您为分隔符属性提供了错误的文件名。更改此行

    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 个像素。另外,1px 通常在 hdpi 及以上的屏幕上看起来更好

    【讨论】:

    • 感谢您的帮助。我也看到了,我改成了正确的名字,但样式不起作用:(
    • 你的活动的背景颜色是什么
    • 我没有为背景选择任何颜色。它是白色的
    【解决方案2】:

    所以我修改了我的 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>
    

    但我仍然不知道为什么第一个不起作用:)

    【讨论】:

      猜你喜欢
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多