Kotlin 布局不适合屏幕

Kotlin Layout Doesn't Fit the Screen

PROBLEM IMAGE CLICK HERE

我的布局不适合屏幕我该如何解决这个问题?谢谢您的帮助。我试图显示来自 ViewModel 的数据。

这是我的 XML 代码

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/detailTopText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView" />
        <ImageView
            android:id="@+id/detailImage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitCenter"
            android:src="@drawable/ic_launcher_background" />
        <TextView
            android:id="@+id/detailDesText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView2" />
    </LinearLayout>
</ScrollView>

尝试在线性布局中设置边距顶部

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:orientation="vertical">

您可以将具有操作栏大小的 paddingTop 或 marginTop 属性添加到 ScrollView

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?android:attr/actionBarSize">

这是您的新布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/detailTopText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView" />

            <ImageView
                android:id="@+id/detailImage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitCenter"
                app:srcCompat="@drawable/flatwoods_img_btn_" />

            <TextView
                android:id="@+id/detailDesText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView2" />


        </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>