最佳答案
您不需要使用第 3 方库来制作 chips .
芯片基本上是一个带有圆形背景的TextView
。您还可以添加一个删除按钮和一个 ImageView
来创建一个 View ,例如用于 Google 联系人的 View 。
出于示例的目的,我将只使用一个简单的 TextView
。首先为芯片创建 UI。
-> shape_chip_drawable.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorPrimary" />
<padding
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp" />
<corners android:radius="30dp" />
</shape>
在您的 Activity 布局文件中,只需将此可绘制资源文件定义为 TextView
背景,如下所示:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/shape_chip_drawable"
android:text="Hello, I'm a simple Chip!"
android:textColor="@android:color/white"
android:textStyle="bold" />
这是创建的 View :
现在我们可以使用 HorizontalScrollView
显示一行筹码(如 GooglePlay 应用程序)或使用 StaggeredGridLayoutManager
构建一个交错的筹码网格。
[编辑]
如果您想将芯片显示为 FlowLayout
,Android 本身并不支持,我们需要使用库。别担心,这是一个很小的变化。
您已在 Gradle 依赖项中添加以下行:
compile 'com.xiaofeng.android:flowlayoutmanager:1.2.3.2'
并使用它设置您的回收站 View 布局管理器:
recyclerView.setLayoutManager(new FlowLayoutManager());
更多详情请点击 GitHub
祝你有美好的一天!如果有帮助,请点赞。
关于android - android支持库中的芯片组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36563739/