【发布时间】:2020-01-28 14:23:16
【问题描述】:
我想显示带有自定义视图和操作按钮的 AlertDialog(自定义视图是具有 layout_height=wrap_content 的 ContraintLayout - LinearLayout 完美)。 ContrainLayout 确实需要很小的尺寸,但 ConstraintLayout 的父级全部出现在屏幕上,因此我看不到操作按钮。这发生在 Android 设备上,其中 Settings -> Display -> Screen Zoom 具有最大值。
View contentView =
getLayoutInflater().inflate(R.layout.dialog_with_checkbox, null);
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
.setPositiveButton("Ok", null)
.setMessage(getString(R.string.dialog_309_message))
.setView(contentView)
.create();
alertDialog.show();
R.layout.dialog_with_checkbox
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="@+id/checkBox"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
为什么约束布局的父级(这是 AlertDialog 的内部实现)都在屏幕上?
【问题讨论】:
-
你检查我的答案了吗?
标签: android android-alertdialog android-constraintlayout