-1

在此处输入图像描述请我在 android xml 中实现这种类型的布局需要帮助。

我已经尝试过RecyclerView这个 ,但我仍然没有得到我想要的。

有任何想法吗?

谢谢

4

2 回答 2

0

您可以ChipGroup在 android Material Design 中使用。

请参考,

芯片和芯片集团

于 2019-10-03T16:25:04.207 回答
0

只需使用材料组件库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);
    }

在此处输入图像描述

于 2019-10-03T19:17:26.073 回答