【发布时间】:2018-05-07 23:10:51
【问题描述】:
我有 ConstraintLayout,里面有 4 个 ImageView,我需要为任何 ImageView 设置权重,例如 LinearLayout,并根据宽度更改视图的高度。
这是我需要的:
所以你可以在这里看到,我有 4 个宽度相同的视图,高度像宽度一样变化。
在我向你展示了我想要做什么之后,这就是我现在的状态:
这是布局:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/label_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintDimensionRatio="W,1:1.15"
app:layout_constraintEnd_toStartOf="@+id/label_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/a" />
<ImageView
android:id="@+id/label_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintDimensionRatio="W,1:1.15"
app:layout_constraintBaseline_toBaselineOf="@id/label_1"
app:layout_constraintEnd_toStartOf="@+id/label_3"
app:layout_constraintStart_toEndOf="@id/label_1"
app:srcCompat="@drawable/a" />
<ImageView
android:id="@+id/label_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintDimensionRatio="W,1:1.15"
app:layout_constraintBaseline_toBaselineOf="@id/label_1"
app:layout_constraintEnd_toEndOf="@id/label_4"
app:layout_constraintStart_toEndOf="@id/label_2"
app:srcCompat="@drawable/a" />
<ImageView
android:id="@+id/label_4"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintDimensionRatio="W,1:1.15"
app:layout_constraintBaseline_toBaselineOf="@id/label_1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/label_3"
app:srcCompat="@drawable/a" />
</android.support.constraint.ConstraintLayout>
注意: 我的资产@drawable/a 是 40X40
我怎样才能得到与我附加的示例相同的结果?
【问题讨论】:
-
第三个ImageView中
constraintEnd有错误导致链不正确。
标签: android android-layout android-constraintlayout