我正在构建一个包含6个链元素的简单纵向布局:
我的目标是: - 空间必须占父母身高的10%(每人5%) - 观看次数必须占父母身高的90%(每次22.5%)
为了达到这个目的,我使用layout_constraintVertical_weight
。
问题是当 weight_sum = 10 时,所有视图都会消失,相反,当sum与10不同时(例如9,9),它可以正常工作。我已经使用了加权视图(使用LinearLayout),但我从未发现过这个问题...
版本:
Android Studio 3.1.2
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
有什么想法吗?! 谢谢:))
<?xml version="1.0" encoding="utf-8"?>
<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">
<Space
android:id="@+id/space"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/view1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_weight="0.5" />
<View
android:id="@+id/view1"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/blue"
app:layout_constraintBottom_toTopOf="@+id/view2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/space"
app:layout_constraintVertical_weight="2.25" />
<View
android:id="@+id/view2"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/yellow"
app:layout_constraintBottom_toTopOf="@+id/view3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view1"
app:layout_constraintVertical_weight="2.25" />
<View
android:id="@+id/view3"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/green"
app:layout_constraintBottom_toTopOf="@+id/view4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view2"
app:layout_constraintVertical_weight="2.25" />
<View
android:id="@+id/view4"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/red"
app:layout_constraintBottom_toTopOf="@+id/space2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view3"
app:layout_constraintVertical_weight="2.25" />
<View
android:id="@+id/space2"
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/view4"
app:layout_constraintVertical_weight="0.5" />
</android.support.constraint.ConstraintLayout>`
差异只是 space2
的layout_constraintVertical_weight
<View
android:id="@+id/space2"
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/view4"
app:layout_constraintVertical_weight="0.49" />