我想讓ScrollView在屏幕底部留出太多空間,因爲它會讓我的兩個按鈕不能顯示。我也不想爲ScrollView手動設置高度。保持ScrollView佔用太高的高度
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
...
android:orientation="horizontal">
<Button .../>
<TextView .../>
<Button .../>
</LinearLayout>
<ScrollView
android:layout_width="math_parent"
android:layout_height="wrap_content">
<ImageView .../>
<ImageView .../>
<ImageView .../>
</ScrollView>
<LinearLayout
...
android:orientation="horizontal">
<Button .../>
<Button .../>
</LinearLayout>
</LinearLayout>
這是我的佈局的通用版本。正在發生的事情是ScrollView一直延伸到屏幕的底部,無論它有多少物品。這會導致屏幕底部的兩個按鈕不可見。
如何在不手動設置ScrollView高度的情況下阻止發生這種情況?
我用我所有的觀點使用android:layout_height="wrap_content"
。
是不是應該自動分配視圖的高度來適應屏幕的高度?
(希望包括圖像,但我的代表處是不夠高,但( - _ - ))
這可能是切換到的RelativeLayout作爲根佈局的好主意。它應該爲您提供工具,讓ScrollView保持在視圖的中心區域內,而無需自己明確計算其高度。 – harism 2011-12-30 15:06:37
感謝您的評論。我已經實施了一個不同的解決方案,但是我一路上學到了更多的東西,我相信你的實現將最適合我想做的事情。一個RelativeLayout將允許我將Buttons錨定到屏幕底部,然後將所有其他UI對象放置在屏幕頂部和按鈕之間。 – edc598 2012-02-01 03:51:28
你的ScrollView應該只有一個孩子。不知道這是不是你的問題的原因。 – Wytze 2014-04-14 14:20:37