【发布时间】:2020-06-04 12:43:03
【问题描述】:
我想在 ImageView 旁边居中对齐 ChipGroup。这是我的 XML:
...
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/locationIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"
app:srcCompat="@drawable/ic_location_on_black_24dp" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/locationChips"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
app:layout_constraintBottom_toBottomOf="@+id/locationIcon"
app:layout_constraintStart_toEndOf="@id/locationIcon"
app:layout_constraintTop_toTopOf="@id/locationIcon">
</com.google.android.material.chip.ChipGroup>
</androidx.constraintlayout.widget.ConstraintLayout>
...
预期结果:
实际结果:
如您所见,芯片没有对齐,而是位于标题文本的顶部,如果文本有一定长度,最后一个芯片也会溢出。我怎样才能解决这个问题?另外,我发现如果 ChipGroup 被限制为父级,最后一个芯片不会溢出。
【问题讨论】:
-
添加您期望的输出图像
-
@backpack :添加了答案。让我知道您想要更改的任何内容
标签: android android-layout android-constraintlayout android-chips