Hiding ListView Header / Hiding Single Divider in a List

*爱你&永不变心* 提交于 2019-12-20 11:54:11

问题


I found this Hide footer view in ListView?. As Yoni poited out correctly, you can hide a header in a ListView by wrapping it into a FrameLayout and setVisibility() of the inner View to View.GONE. This works almost perfect for me, BUT: As the FrameLayout still exists, the ListView adds two dividers to the displayed list. It seems like a single divider with a height of two dividers. Is there a way to hide a single divider of a ListView? Maybe it's possible to change the divider's color to the background, that would be fine for me, too. Any complete other ideas? Perfect!

Please help me. I'm not keen on spending two more hours of trial and error.

Thanks a lot!


回答1:


you can change the dividers color like this:

     <ListView 
    android:id="@+id/android:list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:divider="@android:color/transparent"
    android:dividerHeight="2px"/>



回答2:


Together with hiding or showing your header or footer, use these functions:

setFooterDividersEnabled()
setHeaderDividersEnabled()



回答3:


you can use xml attributes to hide divider for header and footer in ListView

android:footerDividersEnabled="false"
android:headerDividersEnabled="false"



回答4:


For disable divider:

ListView.setDivider(null);


来源:https://stackoverflow.com/questions/4625832/hiding-listview-header-hiding-single-divider-in-a-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!