-1

enter image description herePlease I need help on achieving this type of layout in android xml.

I have tried with RecyclerView and this library but I still did not get what I wanted.

Any ideas?

Thanks

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
bensofter
  • 760
  • 1
  • 14
  • 27

2 Answers2

0

You can make use of ChipGroup in the android Material Design.

Please refer,

Chips and ChipGroup

Saikrishna Rajaraman
  • 3,205
  • 2
  • 16
  • 29
0

Just use the Material Components Library and the Chip component.

You can define it with a layout if it is static:

<com.google.android.material.chip.ChipGroup
    android:id="@+id/chip_group"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <!-- Chips can be declared here, or added dynamically. -->

    <com.google.android.material.chip.Chip
        style="@style/Widget.MaterialComponents.Chip.Entry"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:chipIcon="@drawable/...."
        android:text="@string/..."/>

     .....

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

Or you can do it programmatically.
Define the layout for the single Chip (chip_layout.xml)

<com.google.android.material.chip.Chip
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/Widget.MaterialComponents.Chip.Choice"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

In your code:

ChipGroup reflowGroup = view.findViewById(R.id.chip_group);
for (.....) {
      Chip chip =
          (Chip) getLayoutInflater().inflate(R.layout.chip_layout, chipGroup, false);
      chip.setText(....);
      .....
      chipGroup.addView(chip);
    }

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841