2011-02-14 78 views
6

我有一個佈局,在一行頂部有3個按鈕,然後是一個ListView,後面跟着一個ListView下面的按鈕。 這是我layout.xml文件丟失的按鈕放在ListView之後

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <Button android:id="@+id/btn_top10" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TOP 10"/> 

    <Button android:id="@+id/btn_top100" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TOP 100" 
     android:layout_toRightOf="@id/btn_top10"/> 

    <Button android:id="@+id/btn_showAll" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Show All" 
     android:layout_toRightOf="@id/btn_top100"/> 

    <ListView android:id="@+id/LV_Device" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/btn_top10" 
     android:layout_above="@id/LV_Device"/> 

    <Button android:id="@+id/btn_clearResult" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Clear Results" 
     android:layout_below="@id/LV_Device"/> 

</RelativeLayout> 

這將在下面給出這樣

enter image description here

結果。如果我一定值添加到ListView那麼它的確定,按鈕將展示

enter image description here

但是,如果列表視圖變得比屏幕尺寸更大然後在下面的按鈕,甚至不會滾動到ListView

enter image description here

如何解決這個問題的底部,之後是可見的?我不想讓按鈕固定在屏幕的底部。我希望該按鈕僅顯示在ListView的末尾

回答

5

將您的ListView的高度更改爲0dip。那麼屬性

android:layout_above="@id/LV_Device" 

改變

android:layout_above="@+id/btn_clearResult" 

最後,通過去除android:layout_below修改最後一個按鈕,並添加代替android:layout_alignParentBottom="true"

+0

Thanks..this works ..但正如我已經說過,我不想要按鈕被固定在屏幕的底部。我希望在ListView的末尾看到按鈕。怎麼做? – Shijilal 2011-02-14 03:39:01

+0

然後,您應該切換到LinearLayout並使用權重。但是你應該知道ListView並不真正支持「wrap_content」高度。當您將其設置爲wrap_content時,它總是假設3行的高度。 ListView的要點是能夠有效地滾動數以萬計(或更多)的項目。 – 2011-02-14 06:34:41

+0

hmm.ohk。因爲我無法找到我正在尋找的完美答案..我認爲你的建議接近完美..謝謝。但我真的不認爲線性佈局將能夠解決我的問題。 – Shijilal 2011-02-14 16:38:37

0

Shijilal 你也許嘗試這個 您的頂部按鈕 您的底部組按鈕

+0

意味着......組合頂部和底部按鈕? – Shijilal 2011-02-14 05:40:42

0

把你的RelativeLayout在滾動視圖這樣您的按鈕甚至會後顯示滾動使用這可能工作

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ScrollView01" 
android:layout_width="fill_parent" 
android:paddingTop="10dip" 
android:layout_height="fill_parent" 
android:paddingBottom="10dip"> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <Button 
     android:id="@+id/btn_top10" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TOP 10" /> 
    <Button 
     android:id="@+id/btn_top100" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TOP 100" 
     android:layout_toRightOf="@id/btn_top10" /> 
    <Button 
     android:id="@+id/btn_showAll" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Show All" 
     android:layout_toRightOf="@id/btn_top100" /> 
    <ListView 
     android:id="@+id/LV_Device" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/btn_top10" 
     android:layout_above="@id/LV_Device" /> 
    <Button 
     android:id="@+id/btn_clearResult" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Clear Results" 
     android:layout_below="@id/LV_Device" /> 
</RelativeLayout> 

5

如果你有答案,這是爲那些仍然在尋找你的問題的答案的人。你應該使用ListView.addFooterView(yourbutton)到你的清單。 (但是不要忘記在爲你的listview設置適配器之前先說明這個聲明,如文檔中所述)。

0

Initialy沒有項目在listView.so頂部清除結果按鈕。添加一些項目清除按鈕後下降。但是,當更多的項目被添加清除按鈕下降&超出屏幕分辨率。我想知道,當項目添加清除按鈕時,Initialy會關閉。當清除按鈕到達底部時,它不會進一步下降。您可以在列表視圖中添加更多項目。