2009-12-03 67 views
2

我在設置Android佈局時遇到問題。ListView的Android佈局,然後是屏幕底部的非滾動條文本

我會是一個可滾動的ListView後面跟着一小段文本(TextView),它不會滾動並始終停留在屏幕的底部。

它應該是這樣的:

ListViewItem1

ListViewItem2

ListViewItem3

...

文本這裏的酒吧(總是顯示不論ListView控件的滾動狀態的)

我已經嘗試了一堆不同的變化,但沒有顯示靜態文本

任何想法,我要去哪裏錯了?

TKS!

<?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"> 
    <LinearLayout android:orientation="vertical" 
     android:layout_width="fill_parent" android:layout_height="wrap_content"> 
     <ListView android:id="@+id/list2" android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 
    </LinearLayout> 
    <TextView android:layout_width="fill_parent" 
     android:layout_height="50dip" android:text="Bar of text that always stays at the bottom of the screen" /> 
</LinearLayout> 

回答

3

使用RelativeLayout。使用android:layout_alignParentBottom="true"TextView錨定到底部。剩下的就是ListView

或者,使用單一LinearLayout,設置ListViewandroid:layout_height0pxandroid:layout_weight1,並且TextViewListView作爲LinearLayout的孩子。

+0

你的意思是 「機器人:layout_width 1」 或「機器人:layout_weight到1「? – Nemi 2010-09-01 16:28:47

+0

@Nemi:謝謝你指出 - 我已經解決了我的原始答案。 – CommonsWare 2010-09-01 16:44:35

+0

我嘗試了LinearLayout選項的高度爲0px和layout_weight 1,但沒有奏效。你可以請張貼XML嗎? – 2011-05-11 12:41:52

1

使用android:layout_weight使您的列表視圖填充靜態文本未使用的頁面剩餘部分。

像這樣:

<?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"> 
    <LinearLayout android:orientation="vertical" 
     android:layout_width="fill_parent" android:layout_height="wrap_content"> 
     <ListView android:id="@+id/list2" android:layout_width="fill_parent" 
       android:layout_height="wrap_content" android:layout_weight="1"/><!-- here's the important part--> 
    </LinearLayout> 
    <TextView android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="Bar of text that always stays at the bottom of the screen" /> 
</LinearLayout> 
1

其實,聽起來真是要被使用footer,它的ListView已經和究竟你的描述。

+2

實際上,addFooterView似乎確保您可以將添加的視圖作爲列表的最後一個元素,它無法將其加權到屏幕底部。 – f0ster 2010-10-28 16:54:58

0

基於@CommonsWare答案:

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

    <ListView android:id="@+id/actionsListView" 
     android:layout_height="0px" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:transcriptMode="alwaysScroll"/>  

    <TextView android:text="" 
     android:id="@+id/progressTextLabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:singleLine="true"/> 

</LinearLayout> 
0

試試這個:

希望它能幫助:

<?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="fill_parent"> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="420dp" 
     android:id="@+id/rel"> 
     <ListView 
      android:id="@+id/list2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/rel" 
     android:layout_alignParentBottom="true"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="50dip" 
      android:text="Bar of text that always stays at the bottom of the screen" /> 
    </RelativeLayout> 
</RelativeLayout> 
相關問題