开发者

Listview with button below not working properly

I have a ListView in a dialog and I need to show a button after the list.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="wrap_content">  
<TextView   android:id="@+id/tvwGameOver" android:layout_weight="1" android:gravity="cente开发者_运维知识库r"
            android:textSize="25sp" android:visibility="gone"
            android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<LinearLayout 
  android:id="@+id/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="wrap_content" 
  android:orientation="horizontal" android:footerDividersEnabled="true"
  android:headerDividersEnabled="true" android:layout_below="@id/tvwGameOver">
  <TextView
    android:id="@+id/tvwGameNumberHeader" android:layout_weight="1" android:gravity="right"
    android:text="@string/scores_GameNumber" android:textSize="12sp"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_marginRight="13sp"/>
  <TextView
    android:id="@+id/tvwPlayer0Name" android:layout_weight="1" android:gravity="right"
    android:textSize="12sp" 
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_marginRight="13sp"/>
  <TextView
    android:id="@+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right"
     android:textSize="12sp"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_marginRight="13sp"/>
  <TextView     
    android:id="@+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right"
     android:textSize="12sp"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_marginRight="13sp"/>
  <TextView     
    android:id="@+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right"
    android:textSize="12sp"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_marginRight="13sp"/>
</LinearLayout>


  <ListView
   android:id="@+id/lvwScores" android:layout_below="@id/lloPlayerNames"
   android:layout_width="fill_parent" android:layout_height="wrap_content"  
   android:divider="#FFFFFF" android:dividerHeight="1dip" 
   android:layout_weight="1"
   android:footerDividersEnabled="true" android:headerDividersEnabled ="true"/>

<Button android:id="@+id/btnOK" 
  android:layout_height="wrap_content" android:layout_width="120dip" 
  android:layout_weight="1"
  android:text="OK" android:layout_centerHorizontal="true" 
android:layout_alignParentBottom="true" 

   />
</RelativeLayout>

Problem is that when the list gets to be too big it just passes the button and the button sits over the top of the list.

I tried to add android:layout_below="@id/lvwScores" to the button but then, when the list is empty, I get a button that runs from the bottom of the screen to the bottom of the list.

If I remove the android:layout_alignParentBottom="true" then the dialog is made small.

At the end of the day, I am looking to have the list filling most of the screen even if part of it is still empty (it is a scores screen), with the button at the bottom.

Any ideas?

This is what it looks like when empty:

Listview with button below not working properly

It is great, except that when the list builds up and reaches the bottom is down not stop at the button.


Can you maybe give the list view or the list view's container a margin at the bottom that is the height of the button? Just as a test, give the button a height of 30 dips and have the listview or listview's container have a bottom margin of 30 dips to see if it still runs over behind the button.


The button should have android:layout_below="@id/lvwScores"

alignParentBottom isn't the best approach for RelativeLayouts that do not fill_parent.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜