昨天在項(xiàng)目中遇到一個(gè)以前沒遇到過的問題,就是ScrollView的match_parent不起作用了。所以記錄一下
開始的時(shí)候我的布局是:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...same view
</LinearLayout>
</ScrollView>
LinearLayout里面嵌套的布局高度寫死了,剛好是鋪滿整個(gè)屏幕的,所以這樣寫沒什么問題然而,昨天設(shè)計(jì)要改一下效果圖,需要將LinearLayout里面的布局的高度寫成wrap_content的,這是就出現(xiàn)了問題,發(fā)現(xiàn)現(xiàn)在的布局疊加了,根本沒有鋪滿全屏?。?!OMG當(dāng)時(shí)蒙圈了...
開始一直懷疑是布局寫的有問題,然后接下來的半個(gè)小時(shí)一直在改布局然并卵啊,怎么改布局還是不能鋪滿全屏?。?!所以google了一下,發(fā)現(xiàn)了ScrollView的**android:fillViewport="true"**這個(gè)屬性。把它加上,哇~~鋪滿全屏了,好開心...到這并沒有結(jié)束,我們要搞明白這個(gè)屬性是干啥子用的。源碼中的注釋:
/**
* When set to true, the scroll view measure its child to make it fill the currently
* visible area. */
@ViewDebug.ExportedProperty(category = "layout")
private boolean mFillViewport;
這個(gè)屬性如果設(shè)置為true,ScrollView就會(huì)測(cè)量它的子view,使它的子view填充當(dāng)前的可見區(qū)域