如何在所有 "normal" 设备尺寸的 1 XML 文件上实现滚动视图?

How to implement scrollview on 1 XML file for all "normal" device sizes?

我的 XML 文件中有一个滚动视图。我想使用 "match_parent" 作为布局高度,但我也想在滚动视图顶部放置一个按钮,这样按钮就不会滚动。但是,如果按钮在 Nexus ONE 等较小的手机上消失,我似乎无法做到这一点。我唯一能做的就是使用特定的 layout_Height,比如我目前拥有的 450dp。但是对于 450dp 的布局高度,您可以看到它在 Nexus ONE 尺寸上看起来不错,但在更大的设备尺寸(如 Nexus 6)上,它太小了。

如何使 "Normal" 布局中所有设备尺寸的滚动视图看起来像 Nexus ONE,其中只有一点点 space 留给按钮?

这是我对 layout_height="450dp" 的看法:

连结 6:

两个设备在同一个 XML 文件中:

  <Button
    android:id="@+id/memories"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp"
    android:text="Memories >"
    app:layout_constraintBottom_toTopOf="@+id/scrollView2"
    app:layout_constraintHorizontal_bias="0.502"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ScrollView
    android:id="@+id/scrollView2"
    android:layout_width="0dp"
    android:layout_height="450dp"
    android:layout_marginBottom="6dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:background="#808000"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent">

    <LinearLayout
        android:id="@+id/SavedBroadcasts"
        android:layout_width="304dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="0dp" >

    </LinearLayout>
</ScrollView>

请按照我提到的方式执行您的 XML 代码,它在我的应用程序中正常工作。

<RelativeLayout 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"
    xmlns:tools="http://schemas.android.com/tools">

    <Button
        android:id="@+id/memories"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:text="Memories"
        app:layout_constraintBottom_toTopOf="@+id/scrollView2"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/memories"
        android:layout_marginBottom="6dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:background="#808000"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent">

        <LinearLayout
            android:id="@+id/SavedBroadcasts"
            android:layout_width="304dp"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="0dp">

        </LinearLayout>
    </ScrollView>

</RelativeLayout>

您将在所有设备上看到相同的布局。

Nexus One

连结 6

像素 2