【发布时间】:2018-11-20 22:31:37
【问题描述】:
我有一个ConstraintLayout,我正在垂直对齐几个视图。一些视图使用app:layout_constraintHeight_percent 使其高度占整个布局/屏幕的百分比,而其他视图使用wrap_content 作为它们的高度。
我想要的是将剩余的垂直空间拆分为每个视图之间的相等间距。这可能吗?有什么策略可以实现吗?
这是一个示例布局:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<FrameLayout
android:id="@+id/frame1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#FF0000"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/frame2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#FFFF00"
app:layout_constraintHeight_percent="0.2"
app:layout_constraintTop_toBottomOf="@+id/frame1" />
<FrameLayout
android:id="@+id/frame3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#FF00FF"
app:layout_constraintHeight_percent="0.3"
app:layout_constraintTop_toBottomOf="@+id/frame2" />
<FrameLayout
android:id="@+id/frame4"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#00FFFF"
app:layout_constraintTop_toBottomOf="@+id/frame3" />
</android.support.constraint.ConstraintLayout>
这是它现在的样子:
我想要实现的是在每个彩色矩形之间有相等的空白。
【问题讨论】:
标签: android android-constraintlayout