java流式布局换行_FlowLayout流式布局实战

背景

流式布局在移动端或者前端开发中很常见,特别是在多标签的展示中, 往往起到了关键的作用。然而Android 官方, 并没有为开发者提供这样一个布局,可参考github有名的仓库:https://github.com/google/flexbox-layout

上效果图

14f9054f224b

image.png

实现逻辑

往FlowLayout里面放子View,FlowLayout会横向对齐布局子View同时自动换行,当子View超出FlowLayout最大高度时支持滑动查看

布局文件

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="8dp"

android:text="搜索历史"

android:textColor="@android:color/black"

android:textSize="18sp"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:paddingLeft="10dp"

android:layout_margin="8dp">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape_button_circular"

android:text="水果味孕妇奶粉" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape_button_circular"

android:text="儿童洗衣机" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape_button_circular"

android:text="洗衣机全自动" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape_button_circular"

android:text="小度" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape_button_circular"

android:text="儿童汽车可坐人" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape_button_circular"

android:text="抽真空收纳袋" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape_button_circular"

android:text="儿童滑板车" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape_button_circular"

android:text="稳压器 电容" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape_button_circular"

android:text="羊奶粉" />

android:layout_width="wrap_content"

android:lay

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值