<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" 每行之间的距离
-->
<www.fl.com.flowlayouttext.view.FlowLayout
android:id="@+id/flowlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingBottom="14dp"
android:paddingLeft="21dp"
android:paddingRight="14dp"
app:horizontal_spacing="8dp"
app:vertical_spacing="8dp"/>
</LinearLayout>
//第一步:初始化FlowLayout
flowLayout= (FlowLayout) findViewById(R.id.flowlayout);
//第二步:移除FlowLayout中的所有子布局
flowLayout.removeAllViews();
//第三步:循环创建子View,添加到FlowLayout中
for (int x=0;x<names.length;x++){
//3.1初始化子view
CheckBox checkBox= (CheckBox) View.inflate(context,R.layout.item_flowlayout,null);
checkBox.setText(names[x]);
final int finalX = x;
//3.2设置子view的点击事件
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtil.show(context, names[finalX]);
//遍历FlowLayout中的所有view,如果是当前选中的view,设置为选中状态,其他设置为未选中状态
refreshCheckBox(names[finalX]);
}
});
//3.3将子view添加到FlowLayout中
flowLayout.addView(checkBox);
}
<?xml version="1.0" encoding="utf-8"?> <CheckBox xmlns:android="http://schemas.android.com/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>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有