【问题标题】:How do I create this type of xml layout如何创建这种类型的 xml 布局
【发布时间】:2019-10-03 16:08:10
【问题描述】:

请帮助我在 android xml 中实现这种类型的布局。

我已尝试使用RecyclerViewthis library,但仍然没有得到我想要的。

有什么想法吗?

谢谢

【问题讨论】:

  • 如果您不向我们展示您的尝试和无效,我们将无法帮助您。请给我们看一些代码 sn-ps。
  • 我只需要一个关于最佳方法的想法。我不需要有代码的解决方案。
  • 您应该发布您使用 RecyclerView 尝试过的内容,但没有成功。这是帮助您的唯一方法。 RecyclerView 方法听起来是正确的,您可能需要一个 GridLayoutManager。
  • 不清楚您要达到哪个屏幕。请张贴屏幕。
  • 请查看我的问题

标签: android tags material-components material-components-android android-chips


【解决方案1】:

只需使用Material Components LibraryChip 组件。

如果它是静态的,你可以用布局来定义它:

<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);
    }

【讨论】:

    【解决方案2】:

    您可以在 android Material Design 中使用ChipGroup

    请参考,

    ChipsChipGroup

    【讨论】:

    • 请查看我的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多