设计带有ConstraintLayout
的片段时遇到问题。我希望片段内的两个视图相互堆叠,顶视图的比例限制为4:3,而底视图则填充其余可用空间。因此,我创建了以下布局,并期望了所需的行为:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/view_top"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/view_bottom"
app:layout_constraintDimensionRatio="H,4:3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/view_bottom"
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_toBottomOf="@id/view_top" />
</ConstraintLayout>
但是,此布局不会产生所需的效果,而是在视图之间以及整个布局的顶部和底部之间留有间隙:
为什么将比例应用于两个视图?有没有办法避免这种行为,只将顶视图限制为4:3的比例?]