ScrollView 在 Android Studio 中显示内容,但不在应用程序中显示

ScrollView shows content in Android Studio but not in app

我正在尝试这样的布局

然而,当我将它安装到我的 S7 edge 上时,它看起来像这样:

我不太确定我做错了什么,因为它在设备横向时有效。

这是我的布局文件

<?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:gravity="center_horizontal"
        android:orientation="vertical"
        android:visibility="visible"
android:weightSum="1">
    <TextView
        android:id="@+id/HttpResponse"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Enable Features"
        android:textAlignment="center"
        android:textSize="24sp"
        android:visibility="visible" />

    <ScrollView
        android:layout_width="456dp"
        android:layout_height="wrap_content"
        android:visibility="visible">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:visibility="visible">

        <Switch
            android:id="@+id/switch1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Switch"
            android:visibility="visible" />

        <Switch
            android:id="@+id/switch2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Switch"
            android:visibility="visible" />

        <Switch
            android:id="@+id/switch3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Switch"
            android:visibility="visible" />

    </LinearLayout>
</ScrollView>

<Button
    android:id="@+id/RequestKey"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button"
    android:visibility="visible" />
</LinearLayout>

这里是布局的"Layout and bounds":

(右边的区域是边缘显示,无视)

发生这种情况是因为 ScrollView 的宽度对于纵向来说太大了,请尝试将其设置为 match_parent :

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="visible">

编辑

要将侧边距应用于 ScrollView,请使用:

android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"