开发者

How to hide the horizontal line at the bottom of each item in android listview? [duplicate]

开发者 https://www.devze.com 2023-03-15 09:44 出处:网络
This question already has answers here: How do I remove lines between ListViews on Android? (14 answers)
This question already has answers here: How do I remove lines between ListViews on Android? (14 answers) Closed 8 years ago.

It seems that there is a horizontal line by default at the bottom of each 开发者_如何学Pythonitem in android listview. My problem is: how to let the line not display


You can do using this code..

lvlist.setDivider(null);
lvlist.setDividerHeight(0);


in xml:

android:divider="@null"
android:dividerHeight="0dp"

and in java you can use this:

myList.setDivider(null);
myList.setDividerHeight(0);


Check here: How to change color of Android ListView separator line?

You can try setting the divider height to 0px.


There are different ways to achieve this, but I'm not sure which one is the best (I don't even know is there is a best way). I know at least 2 different ways to do this in a ListView:

1. Set divider to null:

1.1. Programmatically

yourListView.setDivider(null);

1.2. XML

android:divider="@null" (this goes inside your ListView element)

2. Set divider to transparent and set its height to 0 to avoid adding space between listview elements:

2.1. Programmatically:

yourListView.setDivider(new ColorDrawable(android.R.color.transparent));
yourListView.setDividerHeight(0);

2.2. XML

android:divider="@android:color/transparent"
android:dividerHeight="0dp"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号