android - 警报对话框中的可滚动布局,底部有一个按钮(使用约束布局)
问题描述
我必须显示一个警报对话框,其中只有文本区域是可滚动的,并且一个按钮粘在对话框底部,它不是可滚动区域的一部分(按钮应该始终可见)。
我在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()
任何帮助将非常感激。谢谢!
解决方案
推荐阅读
- ruby-on-rails - 如何在表单中为 HMABTM 关系 Rails 添加多条记录
- excel - 如果不满足条件,如何使用 SUMIF 生成空白
- google-developer-tools - 如何在没有 TFA 的情况下重新获得对 Google Developer 帐户的访问权限?
- css - 纯 CSS - 使用 mask-image 和 Radial-gradient 制作菱形形状
- excel - How to remove multiple characters in a string in excel
- c - Programming with C macros
- c# - How to get parameters from stored procedures in a textbox in C # occupying ODBC?
- c# - .NET Web API Blueimp multiple file upload error "Unexpected end of MIME multipart stream. MIME multipart message is not complete."
- python - Tkinter PhotoImage in function doesn't appear
- flutter - 我可以在 fastlane 中使用不同的颤振入口目标吗?