ScrollView中子项设置match_parent失效,无法铺满全屏

2018-11-27 00:23:58

ScrollView中子控件设置match_parent失效,无法占满全屏


1、测试验证:


<ScrollView ....>

<LinearLayout ...>

..........

<LinearLayout

  android:layout_width="match_parent"

                android:layout_height="match_parent"

android:background="@color/cef">

.....

</LinearLayout>

</LinearLayout>

</ScrollView>



当我们设置背景颜色时,可以清楚的看到剩余空间并没有都设置为上面的背景色

2、 方法:


为ScrollView设置如下属性:


android:fillViewport="true"


引用一下别人的解释:



    当ScrollView没有fillVeewport=“true”时,里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了"fill_parent"),而如果LinearLayout的元素设置了fill_parent,那么也是不管用的,因为LinearLayout依赖里面的元素,而里面的元素又依赖LinearLayout,这样自相矛盾.所以里面元素设置了fill_parent,也会当做wrap_content来计算.



  • 2018-01-23 02:22:17

    andorid,把控件置于最顶端。bringToFront的意外发现

     bringToFront方法在SDK中的说明是“Change the view's z order in the tree, so it's on top of other sibling views”,翻译过来就是改变view的z轴,使其处在他父view的顶端。关于bringToFront的实现,网上有很多资料介绍,大体来说就是将这个view从父view中移除,然后再加入父view的顶端。具体实现如何呢?