简体   繁体   English

为什么divider没有显示在listview中@android:id / list?

[英]Why divider is not showing in the listview @android:id/list ?

I have a linear layout that contain the following listview : 我有一个包含以下listview的线性布局:

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:cacheColorHint="#00000000"
    android:divider="#FF0000"
    android:dividerHeight="4dp"
     />

and the layout is used by a ListActivity, the issue is that the following line in ListView xml doesn't take effect : 并且ListActivity使用布局,问题是ListView xml中的以下行不生效:

     android:divider="#FF0000"
    android:dividerHeight="4dp"

and the default divider is set. 并设置默认分隔符。 Do you why this happening and how to fix it? 你为什么会发生这种情况以及如何解决这个问题?

its an difference of the dp and px. 它是dp和px的差异。

use this 用这个

android:dividerHeight="4px"

instead of 代替

android:dividerHeight="4dp"

and use this also if you want 如果你愿意,也可以使用它

int[] colors = {0, 0xFFFF0000, 0}; // red for the example
myList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
myList.setDividerHeight(1);

you will get it.. 你会得到的..

For me this is working perfectly: 对我来说,这是完美的工作:

 <ListView
     android:id="@+id/listHomeScreen"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:cacheColorHint="#000"
     android:divider="#7F7F7F"
     android:dividerHeight="1dip"
     android:listSelector="@android:color/transparent" >
</ListView>

Ensure we are not overriding android:dividerHeight or divider color. 确保我们没有覆盖android:dividerHeight或divider颜色。

There is bug in Android Lollipop 5.0 if you have overridden setEnabled() then this happens. Android Lollipop 5.0中存在错误,如果你已经覆盖了setEnabled(),那么就会发生这种情况。 Check ot this question for more info ListView divider not showing in Android 5 请查看此问题以获取更多信息ListView分隔符未在Android 5中显示

Its resolved now . 它现在解决了 the issue is before i decide to make the list in xml i had this code in my listActivity to add divider which was overriding the xml : 问题是在我决定在xml中创建列表之前我在listActivity中有这个代码来添加覆盖xml的divider:

int[] colors = { 0xA8A8A8A8, 0xFFFFFFFF, 0xA8A8A8A8 };
getListView().setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
getListView().setDividerHeight(1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM