Android上的ListView和TextView之间的分隔符

问题描述:

正如您在下面的图像中看到的那样,ListView在TextView(footer)之前出现一条黑线。Android上的ListView和TextView之间的分隔符

enter image description here

我无法理解,如果是由于列表视图或TextView的的顶部填充的底部填充,所以我试图操纵XML布局添加机器人:layout_marginBottom =“0像素”和android:paddingBottom =“0px”放入到textview中,android:paddingTop =“0px”和android:layout_marginTop =“0px”,但没有任何效果!

请帮助我,因为我不知道如何解决问题!

这里布局的个XML ...

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/header" 
    android:id="@+id/header" 
    android:gravity="center" 
    android:textSize="22sp" 
    android:background="#777777" 
/> 
<ListView 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:id="@+id/items_list" 
    android:divider="#00000000" 
    android:dividerHeight="0px" 
    android:footerDividersEnabled="false" 
    android:layout_marginBottom="0px" 
    android:paddingBottom="0px" 
/>  
<TextView 
    android:paddingTop="0px" 
    android:layout_marginTop="0px" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/footer" 
    android:gravity="center" android:textSize="22sp" 
    android:background="#777777/> 
</LinearLayout> 

在这里,项目的布局,列表视图

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingBottom="0px" 
    android:layout_marginBottom="0px" 
    android:background="#777777"> 

    <TextView 
     android:layout_width="fill_parent" 
     android:text="Item List" 
     android:layout_height="wrap_content" 
     android:id="@+id/item" 
     android:textSize="22sp" 
    /> 
    <TextView 
     android:layout_width="fill_parent" 
     android:text="List Item bottom" 
     android:layout_height="wrap_content" 
     android:id="@+id/item2" 
     android:textSize="14sp" 
     android:layout_below="@id/item" 
     android:layout_alignParentBottom="true" 
    /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:text="List Item right" 
     android:layout_height="wrap_content" 
     android:id="@+id/item3" 
     android:textSize="16sp" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     /> 
</RelativeLayout> 
+0

嗯,我不知道为什么那条黑线也在那里,但也许你应该尝试使用[ListView.addFooterView()](http://developer.android.com/reference/android/widget/ListView .html#addFooterView(android.view.View)) – dmon 2011-06-03 17:09:12

尝试设置了android:footerDividersEnabled属性设置为false,看看是否有帮助。

看起来这是一个错误。有一个hackaround。在你的ListView中写下:

<ListView ... android:layout_marginBottom="-3dp" /> 

这会解决这个问题。

说到这里,我想提一个更多,你应该使用ListView.addFooterView()时间,或者你可以使用layout_weight

<ListView  
    android:layout_width="fill_parent" 
    android:layout_height="0dp"   
    android:layout_weight="1" 
    android:background="#888888" 
    ... 
/> 

enter image description here

选择符合您需求的最佳办法。但请注意,“-3dp”是一种破解,不应该使用(除非你绝望:)。