我想使ImageGroup旁边的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限制为父代,则最后一个芯片不会溢出。
由于您基于locationIcon
设置了约束,并且在locationIcon
中设置了页边距上限,因此芯片未对齐。>
从marginTop
中删除ImageView
android:layout_marginTop="8dp"
也删除
ChipGroup
约束
app:layout_constraintBottom_toBottomOf="@+id/locationIcon"