如何删除 Android 上 ListViews 之间的线条?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1914477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I remove lines between ListViews on Android?
提问by deepthi
I'm using two ListView
s like this:
我正在使用两个ListView
这样的:
<ListView
android:id="@+id/ListView"
android:text="@string/Website"
android:layout_height="30px"
android:layout_width="150px"
android:scrollbars="none"
android:transcriptMode="normal"/>
<ListView
android:id="@+id/ListView1"
android:text="@string/Website"
android:layout_height="30px"
android:layout_width="150px"
android:scrollbars="none"
android:transcriptMode="normal"/>
There is one blank line between the two ListView
s. How do I remove it?
两个ListView
s之间有一个空行。如何删除它?
回答by dasilvj
To remove the separator between items in the same ListView, here is the solution:
要删除同一 ListView 中项目之间的分隔符,解决方法如下:
getListView().setDivider(null);
getListView().setDividerHeight(0);
developer.android.com # ListView
developer.android.com # ListView
Or, if you want to do it in XML:
或者,如果您想在 XML 中执行此操作:
android:divider="@null"
android:dividerHeight="0dp"
回答by Amintabar
If you want to remove a divider line, use this code:
android:divider="@null"
If you want to add a space instead of a divider line:
android:divider="@android:color/transparent" android:dividerHeight="5dp"
如果要删除分隔线,请使用以下代码:
android:divider="@null"
如果要添加空格而不是分隔线:
android:divider="@android:color/transparent" android:dividerHeight="5dp"
So, you can use any drawable or color in the divider attribute.
因此,您可以在分隔线属性中使用任何可绘制或颜色。
回答by Sotti
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 two different ways to do this in a ListView:
有不同的方法可以实现这一点,但我不确定哪个是最好的(我什至不知道是否有最好的方法)。我知道至少有两种不同的方法可以在 ListView 中做到这一点:
1. Set divider to null:
1. 将分隔符设置为空:
1.1. Programmatically
1.1. 以编程方式
yourListView.setDivider(null);
1.2. XML
1.2. XML
This goes inside your ListView element.
这在您的 ListView 元素中。
android:divider="@null"
2. Set divider to transparent and set its height to 0 to avoid adding space between listview elements:
2.将divider设置为透明,将其高度设置为0,以避免在listview元素之间添加空间:
2.1. Programmatically:
2.1. 以编程方式:
yourListView.setDivider(new ColorDrawable(android.R.color.transparent));
yourListView.setDividerHeight(0);
2.2. XML
2.2. XML
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
回答by Khalid Taha
In XML:
在 XML 中:
android:divider="@null"
Or in Java:
或者在 Java 中:
listView.setDivider(null);
回答by Saneesh
Set divider to null:
将分隔符设置为空:
JAVA
爪哇
listview_id.setDivider(null);
XML
XML
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
/>
回答by Muhammad Shafqat
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:dividerHeight="0dp"/>
回答by sandeepmaaram
You can put below property in listview tag
您可以将以下属性放在 listview 标签中
android:divider="@null"
(or)
programmatically listview.Divider(null);
here listview
is ListView
reference.
(或)以编程方式listview.Divider(null);
这里listview
是ListView
参考。
回答by Mads Kristiansen
Or in XML:
或者在 XML 中:
android:divider="@drawable/list_item_divider"
android:dividerHeight="1dp"
You can use a color for the drawable (e.g. #ff112233), but be aware, that pre-cupcake releases have a bug in which the color cannot be set. Instead a 9-patch or a image must be used..
您可以为可绘制对象使用颜色(例如#ff112233),但请注意,纸杯蛋糕之前的版本存在无法设置颜色的错误。相反,必须使用 9-patch 或图像。
回答by Zia
You can try the following. It worked for me...
您可以尝试以下操作。它对我有用...
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
回答by Fred
I find it easier to implement it in the XML file as it can be harder to trace the line of code in a class with hundreds of lines. For the XML you can use "null":
我发现在 XML 文件中实现它更容易,因为在具有数百行的类中跟踪代码行会更困难。对于 XML,您可以使用“null”:
android:divider="@null"