Android ScrollView-第一个视图填充整个屏幕

Android ScrollView-第一个视图填充整个屏幕,android,layout,scrollview,Android,Layout,Scrollview,我想让第一个视图填满整个屏幕,当用户向下滚动时,会显示第二个视图,但是ScrollView将无法工作 我用ConstraintLayout()试过了,但还是不行 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pa

我想让第一个视图填满整个屏幕,当用户向下滚动时,会显示第二个视图,但是
ScrollView
将无法工作
我用
ConstraintLayout
()试过了,但还是不行

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
            <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="1" />    
            </RelativeLayout>
            <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="2" />
            </RelativeLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>


如何解决这个问题?

假设您的scrollview中的第一个RelativeLayout是“view1”。您应该编写如下示例所示的代码:

val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
val displayHeight = displayMetrics.heightPixels

view1.layoutParams.height = displayHeight
可能是重复的