开发者

Separator between ListView and TextView on Android

As you can see in image below, under the ListView appear a black line before the TextView (footer).

Separator between ListView and TextView on Android

I'm not able to understand if it's due a bottom padding of the listview or a top padding of the textview, so I've tried manipulating the xml layout adding android:layout_marginBottom="0px" and android:paddingBottom="0px" into the listview and android:paddingTop="0px" and android:layout_marginTop="0px" into the textview but nothing works!

Please help me because I've no idea how to solve the problem!!!

Here the xmls of the layout...

<?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>

And here the layout of the item into the listview

<?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>


It looks like this is a bug. There is a hackaround. In your ListView write this:

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

This will fix this particular issue.

Having said that, I want to mention one more time that you should use ListView.addFooterView() or you can use layout_weight:

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

Separator between ListView and TextView on Android

Select the approach that fits you needs best. But note that "-3dp" is a hack, and should not be used (unless you are desperate :).


Try setting the android:footerDividersEnabled attribute to false and see if that helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜