【发布时间】:2020-05-29 11:21:24
【问题描述】:
我在设计带有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 比例?
【问题讨论】:
标签: android android-layout android-constraintlayout