前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >官方FlowLayout的使用,以及使用TagFlowLayout的一个问题

官方FlowLayout的使用,以及使用TagFlowLayout的一个问题

作者头像
Jingbin
发布2019-06-19 10:24:41
6.2K0
发布2019-06-19 10:24:41
举报
文章被收录于专栏:Android 技术栈Android 技术栈

问题

一直使用的是鸿洋的TagFlowLayout,用于显示标签的自动换行问题。 但最近遇到一个问题: 如果内容过长则右边的内容会缺一块,如果是一个圆角背景则会被切掉一点。为此我花费了大量时间,用官方的FlowLayout替代解决这个问题。

需要注意的是,官方的也不能在添加的view上加左右的margin,否则也会出现上述问题,而TagFlowLayout也是代码里添加了增加margin造成的。

FlowLayout的使用

代码语言:javascript
复制
        <android.support.design.internal.FlowLayout
            android:id="@+id/tfl_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="17dp"
            android:layout_marginTop="10dp"
            android:layout_marginEnd="10dp"
            app:itemSpacing="8dp"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tv_title"
            app:lineSpacing="8dp" />

不能在添加的view上加左右的margin,我们可以使用属性:

  • app:itemSpacing 每个tag之间的间隔
  • app:lineSpacing 行距

代码添加view:

代码语言:javascript
复制
    private void showTagView(android.support.design.internal.FlowLayout flowLayout, final List<ArticlesBean> beanList) {
        flowLayout.removeAllViews();
        for (int i = 0; i < beanList.size(); i++) {
            TextView textView = (TextView) View.inflate(flowLayout.getContext(), R.layout.layout_navi_tag, null);
            textView.setText(Html.fromHtml(beanList.get(i).getTitle()));
            flowLayout.addView(textView);
            });
        }
    }

注意:

  • 完整路径名:android.support.design.internal.FlowLayout
  • app:itemSpacing 未知原因不能直接关联属性
  • 不能在view里直接设置 margin ,会出现圆角背景会被切掉的问题。
  • 如果使用 ConstraintLayout,则FlowLayout使用:layout_width="match_parent"
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.06.17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题
  • FlowLayout的使用
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档