我想在android中爲ScrollView設置50%的屏幕高度,爲ListView設置50%的屏幕高度。防止Android ListView佔用幾乎所有的屏幕高度
要做到這一點,我已經把每個的權重設置爲「1」。
這樣的:
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip">
<ScrollView android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1">
<TableLayout android:id="@+id/my_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="0">
<TableRow android:padding="5dip"
android:id="@+id/fault_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/table_title"
android:paddingRight="20dip"/>
</TableRow>
<!-- More rows are added at run time. -->
</TableLayout>
</ScrollView>
<ListView android:id="@+id/comments"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"></ListView>
</LinearLayout>
當兩個滾動型和ListView中有太多的內容顯示不滾動這個完美的作品。
當ScrollView只需要20%的屏幕和ListView需要70%的ListView增長到70%,因此它可以不滾動顯示。這不是我預期會發生的,但是很好。
我遇到的問題是,當ListView有這麼多的數據,它需要整個屏幕顯示和滾動視圖只有1或2行數據。在這種情況下,ListView增長几乎佔據了整個高度,並留下相當於滾動視圖的大約一行文本的空間。
我似乎無法得知我的頭如何保留ScrollView的一定比例的屏幕,無論ListView有多大。
p.s. ScrollView可以抓取的空間量似乎與其子表中的行數成正比。當這隻有1時,滾動視圖只有大約半釐米的高度。
我不知道這是怎麼回事爲了解決這個問題,但是你不需要兩個'LinearLayout'封裝兩個內部視圖(權重在'LinearLayout'的任何子節點中工作),我會嘗試將根佈局的高度設置爲'fill_parent'。 – bigstones 2011-03-01 15:37:22
感謝您的信息。刪除違規佈局。但你說得很對,這並不能解決問題。 – rpcutts 2011-03-01 16:12:14
你可以編輯這個問題來使用你的新佈局嗎? – 2011-03-01 16:17:07