【发布时间】:2022-01-14 21:13:21
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data></data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<View
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/my_color"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<layout>
左图来自 XML,但启动应用程序后,对话框显示不正确。我猜这就像 ConstraintLayout 的高度是 wrap_parent 并且无法检测到底部。
我该如何解决这个问题?
【问题讨论】:
-
试试This thread。如果您使用自定义视图已经更好,请转到
DialogFragment或Dialog。AlertDialog是一个专用对话框,仅适用于警报。你可以用AlertDialog做同样的事情,因为它确实是一个对话框。 -
您是使用
requireContext()作为AlertDialog.Builder上下文还是仅使用null?
标签: android android-alertdialog android-constraintlayout