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

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

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

我在stackoverflow https://stackoverflow.com/a/9326544/1554537中找到了使用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()

任何帮助将不胜感激。谢谢!

x551857914h 回答:“警报”对话框中的可滚动布局,底部有一个按钮(使用约束布局)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3141966.html

大家都在问