请我在 android xml 中实现这种类型的布局需要帮助。
我已经尝试过RecyclerView
这个库 ,但我仍然没有得到我想要的。
有任何想法吗?
谢谢
如果它是静态的,您可以使用布局定义它:
<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);
}