对话框:溢出的 ScrollView 内容

Dialog: Overflowing ScrollView Content

新手 android 开发人员在这里。我的对话框有这样的布局:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llParent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ScrollView
        android:id="@+id/svChild"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    ... content goes here

    </ScrollView>

    <Button
        android:id="@+id/btnCancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/svChild"
        android:text="CANCEL"/>

    <Button
        android:id="@+id/btnOk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/svChild"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:text="OK" />

</RelativeLayout>

ScrollView的内容溢出屏幕时,它会覆盖下面的按钮。有时更改布局的某些属性时按钮已经在屏幕外。

我想要的:

谢谢

使用下面的代码可以正常工作

<RelativeLayout 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"
tools:context="com.demo.example.activity.ScrollDemo">


<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/btnButton"
    android:id="@+id/scrollView">

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

        //Place your content here

    </LinearLayout>
</ScrollView>



<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button"
    android:id="@+id/btnButton"
    android:layout_alignParentBottom="true" />

</RelativeLayout>

依赖关系在这里最为重要。

如果您有任何问题,请随时发表评论。