2012-10-27 125 views
-2

所以我有這種佈局方案,我還沒有找到任何理想的解決方案。我已經畫了一個,我希望這是可以理解的。ListView + textview下面的佈局問題

enter image description here

現在我的ListView始終處於底部的LinearLayout以上。當ListView有幾個項目時,TextView就在下面,看起來很好。但是,當它有很多項目時,它會壓碎TextView,它們之間應始終存在,無論在LW和底部容器之間。

任何人都可以給我一個XML例子,實現這一目標嗎?

回答

1

您可以包裝ListViewLinearLayout並設置權重來此Linearlayout,該TextView和底部LinearLayout。 (您必須將ListView包裝在LinearLayout內,因爲您無法將權重應用於ListView)。

+0

這工作得很好。我正在使用一個相對佈局作爲根,這給我的問題 –

-1

如果我不想錯過,請嘗試創建一個ListView,例如wrap_content?而TextView總是低於ListView?如果我沒有錯,那麼,這就是你需要:以上

<LinearLayout // Your list view and TextView in a same linear layout 
    android:layout_alignParentTop="true" 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" // With this specific height, your TextView will 
            // always in this range! 
    android:orientation="vertical" > 

    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" > 
    </ListView> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:layout_marginBottom="91dp" 
     //layout_gravity = "right"?? I'm not sure, you should make it right alignment 
    /> 
</LinearLayout> 

<LinearLayout /> // This is your linear layout at the Bottom, 2 Lineary layout is 
       // putted in a Relative layout 

佈局給你一個ListView在頂部,而TextView的是下面的的LinearLayout在底部。試試看!!

+1

你**不能**限制ListView的高度。您必須將其包裝在LinearLayout中。 – Ahmad

+0

@Ahmad:是啊!我知道,但對我來說,上面的代碼運行良好!你有試過嗎? –