天天看點

ScrollView嵌套LinearLayout布局不能撐滿全屏的問題

當ScrollView裡的元素想填滿ScrollView時,使用"fill_parent"或者"match_parent"是不管用的,必需為ScrollView設定:android:fillViewport="true"。  

如果ScrollView中的元素高度超過目前螢幕的高度時,這個設定将毫無意義。但是我們不能保證每個使用ScrollView的布局都能撐滿整個螢幕,是以此時設定android:fillViewport="true"就是必然的了,因為如果沒有加入此設定,裡面的元素會按照wrap_content來計算,無論你設定了"fill_parent"還是"match_parent"都是無效的。

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
</ScrollView