Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 警报对话框中的可滚动布局,底部有一个按钮(使用约束布局)_Android_Scrollview_Android Alertdialog_Android Constraintlayout - Fatal编程技术网

Android 警报对话框中的可滚动布局,底部有一个按钮(使用约束布局)

Android 警报对话框中的可滚动布局,底部有一个按钮(使用约束布局),android,scrollview,android-alertdialog,android-constraintlayout,Android,Scrollview,Android Alertdialog,Android Constraintlayout,我必须显示一个警报对话框,其中只有文本区域是可滚动的,并且对话框底部粘贴了一个按钮,该按钮不是可滚动区域的一部分(按钮应始终可见) 我在stackoverflow中找到了使用RelativeLayout的解决方案 但我需要使用约束布局 当我使用约束布局时,滚动视图总是将按钮推出屏幕 这是我尝试的约束布局 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayo

我必须显示一个警报对话框,其中只有文本区域是可滚动的,并且对话框底部粘贴了一个按钮,该按钮不是可滚动区域的一部分(按钮应始终可见)

我在stackoverflow中找到了使用RelativeLayout的解决方案

但我需要使用约束布局

当我使用约束布局时,滚动视图总是将按钮推出屏幕

这是我尝试的约束布局

<?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"
    android:paddingStart="30dp"
    android:paddingTop="25dp"
    android:paddingEnd="30dp"
    android:paddingBottom="25dp">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fadeScrollbars="false"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toTopOf="@id/button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/titleTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/title"
                android:textSize="20sp"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/bodyTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:gravity="start"
                android:text="@string/body_msg"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/titleTextView" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_name"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
任何帮助都将不胜感激。谢谢

val view = this.layoutInflater.inflate(R.layout.scroll_layout, null)
            val dialog = AlertDialog.Builder(this)
                .setView(view)
                .create()
            dialog.show()