[英]Setting minimum height of a view to be the height of its parent
在ScrollView內部,我有一個LinearLayout。 LinearLayout可以達到所需的高度,但是我希望其最小高度至少與其父級(ScrollView)一樣高。
<ScrollView
...>
<LinearLayout
...
android:layout_marginTop="@dimen/some_margin"
android:minHeight="match_parent">
這是行不通的。 minHeight
不會接受"match_parent"
。 那么我該如何處理呢?
您可以在xml文件中使用ScrollView的android:fillViewport="true"
屬性,如下所示:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Rest of the children-->
</LinearLayout>
</ScrollView>
因此,您只想避免在LinearLayout中的內容沒有填滿ScrollView允許的空間時浪費資源? 僅將LinearLayout高度設置為:
android:layout_height="match_parent"
您可以在ScrollView上設置相同的值,以使其也適合其自己的父級,但並非絕對必要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.