Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chipgroup margin and multilines

I'm developing an app with chips.

I have a constraint layout with a TextView and a ChipGroup. The chips are added programmatically.

This is the layout

...
<com.google.android.material.chip.ChipGroup
    android:id="@+id/chipGroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:background="@android:color/holo_red_dark"
    android:gravity="end"
    app:layout_constraintBottom_toTopOf="@+id/chartView"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/textView"
    app:layout_constraintTop_toBottomOf="@+id/project3">

</com.google.android.material.chip.ChipGroup>

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="24dp"
    android:text="Pippo"
    android:textColor="@color/greenPositive"
    app:layout_constraintBottom_toTopOf="@+id/chartView"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/project3" />
...

The activity appears as the screenshot (I have put a red background in the chipgroup to show the area)

enter image description here

  • The ChipGroup is constrainted to the end of textview, but ignore this constraint and the margin.
  • At the end a Chip is truncated, but the ChipGroup has a 16dp of margin at the end.
  • The first and second row are not aligned with the first row
  • I put gravity end in the ChipGroup, but the chips are aligned to start.

How to solve all these problems?

like image 664
TizioIncognito Avatar asked May 12 '26 23:05

TizioIncognito


1 Answers

Adding app:chipSpacingVertical attribute to ChipGroup View will solve this.

 <com.google.android.material.chip.ChipGroup
        android:id="@+id/chipGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:chipSpacingVertical="4dp"/>
like image 159
Ozan ERTÜRK Avatar answered May 14 '26 14:05

Ozan ERTÜRK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!