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来计算.



  • 2020-12-29 16:20:29

    使用console进行 性能测试 和 计算代码运行时间

    对于前端开发人员,在开发过程中经常需要监控某些表达式或变量的值,如果使用用 debugger 会显得过于笨重,最常用的方法是会将值输出到控制台上方便调试。 最常用的语句就是console.log(expression)了。

  • 2021-01-05 15:41:42

    nodejs修改时区

    ​let date = new Date(); date.setHours(date.getHours() + 8);

  • 2021-01-06 23:09:38

    mp3解码器转PCM合并

    首先,为了混合两个音频文件,您需要操纵它们的原始表示;由于MP3文件被压缩,您无法直接访问信号的原始表示.您需要对压缩的MP3流进行解码,以便“理解”您的音频信号的波形,然后可以混合使用.