当前位置: 移动技术网 > 移动技术>移动开发>Android > ScrollView控件不能撑满全屏问题的解决方案

ScrollView控件不能撑满全屏问题的解决方案

2020年09月21日  | 移动技术网移动技术  | 我要评论
今天开发的时候,ScrollView不能撑满全屏,这个问题一想了很多方案,最后记一下笔记初始布局:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"

今天开发的时候,ScrollView不能撑满全屏,这个问题一想了很多方案,最后记一下笔记
初始布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#f6f7fb"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="#ff8900" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:background="#ff00D3A9"
                android:text="Button" />
        </LinearLayout>

    </ScrollView>

</LinearLayout>

在这里插入图片描述
实际上的需求是按钮置置底,然后LinearLayout和Button控件之间用空白填充
经过反复尝试,有效的方案如下
在这里插入图片描述
具体的做法是:

ScrollView设置height为“0dp”,权重weight为“1”,最重要的一点是设置fillViewport=“true”,使得子布局和ScrollView一样高,如果子布局本来就超过了ScrollView,该属性就没有意义。
然后在Button上面加一个Space控件,这个是空白填充的作用,高度和宽度全部使“match_parent”,weight为“1”

最终效果:
在这里插入图片描述
写在最后:原创不易,觉得对自己有帮助的小老弟,欢迎点赞评论~~~

本文地址:https://blog.csdn.net/m0_37293461/article/details/108705969

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网