文字包装在两行 - recyclerview

Nil*_*kar 1 android textview android-recyclerview

我正在设计具有预期UI的应用程序

预期

我正在使用RecyclerView

StaggeredGridLayoutManager manager=new StaggeredGridLayoutManager(3,1);
        recyclerView.setLayoutManager(manager);
Run Code Online (Sandbox Code Playgroud)

这是行xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/padding_8dp"
    android:layout_marginLeft="@dimen/padding_4dp"
    android:layout_marginRight="@dimen/padding_4dp"
   >

    <com.skcsllp.mutterfly.views.widgets.MfTextView
        android:id="@+id/tagName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/textview"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:textSize="@dimen/text_18"

        android:background="@drawable/selector_tags"
        android:textColor="@color/tags_text_color"

        />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

使用这么多我得到的输出

我得到了什么

我不希望标签进入第二行.我知道我已经使用跨度计数为3,因此在一行中获得3个标签,但有没有办法避免文本换行在两行?

Rav*_*avi 5

而不是RecyclerView我建议你使用AndroidTagView

需要添加依赖

dependencies {
   compile 'co.lujun:androidtagview:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)

在你的主xml中,而不是 RecyclerView

<co.lujun.androidtagview.TagContainerLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:padding="10dp"
app:container_enable_drag="false"
app:horizontal_interval="10dp"
app:vertical_interval="10dp"
app:tag_clickable="true"
app:tag_theme="pure_teal" />
Run Code Online (Sandbox Code Playgroud)

在你的活动/片段中

TagContainerLayout mTagContainerLayout = (TagContainerLayout) findViewById(R.id.tagcontainerLayout);
mTagContainerLayout.setTags(List<String> tags);
Run Code Online (Sandbox Code Playgroud)

你将得到类似下面的输出,为了更多你可以参考该库,他们也提供了很好的示例项目.

在此输入图像描述

其他有用的库列在下面:

https://github.com/loopeer/MultiTextTagView
https://github.com/klinker41/android-chips
https://github.com/ApmeM/android-flowlayout
https://github.com/blazsolar/FlowLayout