Android 5中未显示ListView分隔符
我有一个简单的listview,我为它定义了一个可用于分隔符的自定义绘图。我已将分隔高度定义为1dp。listview位于片段中Android 5中未显示ListView分隔符,android,android-layout,android-listview,android-5.0-lollipop,Android,Android Layout,Android Listview,Android 5.0 Lollipop,我有一个简单的listview,我为它定义了一个可用于分隔符的自定义绘图。我已将分隔高度定义为1dp。listview位于片段中 <shape android:shape="line" > <stroke android:color="@color/custom_color" /> <gradient android:height="1dp" /> </shape> 它适用于除L以外的所有Andro
<shape
android:shape="line" >
<stroke
android:color="@color/custom_color" />
<gradient android:height="1dp" />
</shape>
它适用于除L以外的所有Android版本
我遗漏了什么吗?更新的答案 进一步测试后,似乎只有当分隔器的高度严格小于为ListView设置的
分隔器高度时,分隔器才会显示。例如:
custom_divider.xml
(请注意,分隔器高度由android:width
指定)
布局xml
布局xml
您应该使用android:shape=“rectangle”
而不是android:shape=“line”
使其在每个android版本上都能工作。。。(同时将行程
更改为实心
)
玩得开心 您的列表项是否通过重写isEnabled()以返回false而被禁用?Android L中有一个变化(bug?),如果某个项被禁用,它会导致列表项分隔符被隐藏。我遇到了同样的问题,我的列表除法器在除L之外的所有地方都工作,这就是原因
以下是一些讨论过这一点的帖子,以及谷歌提出的一个问题:
评论如下:
如果是这种情况,听起来您可能需要使用自定义视图手动绘制分隔符,并在列表中将分隔符设置为null。我将尝试同样的方法。高度属性不是渐变标记下的属性。使用大小属性,如下所示
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/holo_blue_dark" />
<size android:height="1px" />
</shape>
我会尝试使用“2dp”,但如果不是这样,我不知道会缺少什么。我也尝试了4dp。没有帮助。listview.setdivider(R.drawable.line);尝试使用px而不是dp,因为对于ldpi,1dp=0.75像素,因此它向下舍入为0,并且不会绘制分割线。这一点很好。但是我在Nexus5上运行这个(它使用xxhdpi资产),谢谢你的解决方案!!
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:divider="@drawable/custom_divider"
android:dividerHeight="2dp"/>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:width="1dp"
android:color="$ffff0000" />
</shape>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:divider="@drawable/custom_divider"
android:dividerHeight="1dp"/>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:width="10dp"
android:color="$ffff0000" />
<gradient android:height="1dp" />
</shape>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:divider="@drawable/custom_divider"
android:dividerHeight="20dp"/>
<shape
android:shape="rectangle" >
<solid android:color="@color/custom_color" />
<gradient android:height="1dp" />
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/holo_blue_dark" />
<size android:height="1px" />
</shape>