现在商城类的APP几乎都要用到流式布局来实现选择属性功能,在我的demo中是通过FlowLayout工具类实现流式布局
使用起来非常简单,十几行代码就可以实现;
在我们的项目中大部分都是单选效果,为了防止用到多选,demo中也实现了多选;
FlowLayout大家不用研究怎么实现的,只要会使用就好;
就好比谷歌提供的ListView条目点击事件一样,只要会用就好,没必要研究个所以然;大家在用的时候直接从demo中复制到项目中即可;
大家可以将FlowLayout理解为一个线性布局;将准备好的一个个子view添加到FlowLayout中即可;
首先看下布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> <!-- app:horizontal_spacing="8dp" 每列之间的距离 app:vertical_spacing="8dp" 每行之间的距离 --> </apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@null" android:textSize="15sp" android:paddingLeft="5dp" android:paddingRight="5dp" android:background="@drawable/item_bg_select" android:textColor="@drawable/text_color" android:paddingTop="3dp" android:paddingBottom="3dp"> </CheckBox>单选到此结束,大家可能感觉多选比单选要难,其实多选比单选还要简单,以上代码只需去除子view点击事件refreshCheckBox()方法即可实现多选;
点击打开链接免费下载源码
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。