Просто используйте Библиотека компонентов материала и Chip
.
Вы можете определить его с помощью макета, если онстатические:
<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>
Или вы можете сделать это программно.
Определить макет для одного чипа (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"/>
В вашем коде:
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](https://i.stack.imgur.com/DT0SN.png)