我有一个带有 ConstraintLayout 的 AlertDialog 作为视图,并且所有子项的高度为0dp
,即匹配约束:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxHeight="400dp">
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<!-- Other children -->
我希望对话框在屏幕上占据尽可能高的高度,最大为400dp
. 然而,上面的布局会产生一个高度为 0 的对话框,不可见。
我尝试使用dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
. 该对话框占据了整个屏幕高度,但 ConstraintLayout 仍然不可见。
有没有办法做到这一点?