自定义控件 - 流式布局:TagFlowLayout
2024-08-23 17:46:33
在项目中需要用到流式布局的样式,此文学习鸿洋大神的FlowLayout控件,学习使用一下。出自 http://blog.csdn.net/lmj623565791/article/details/38352503
流式布局的特点:
- 支持setAdapter设置数据源
- 支持单选、多选
- 点击回调事件
效果图:
使用方法
1 gradle依赖
compile 'com.hyman:flowlayout-lib:1.1.2'
2 布局文件中使用
<com.zhy.view.flowlayout.TagFlowLayout
android:id="@+id/tagfl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:max_select="1" />
app:max_select = 1 表示单选
3 代码中设置数据源
List<String> datas = new ArrayList<>();
TagAdapter<String> adapter= new TagAdapter<String>(datas) {
@Override
public View getView(FlowLayout parent, int position, String o) {
TextView view = (TextView) LayoutInflater.from(mContext).inflate(R.layout.item_tag, parent,false);
view.setText(o);
return view;
}
};
tagFlowLayout.setAdapter(adapter);
4 设置textview资源文件布局
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/margin"
android:textColor="@drawable/b_text_color"
android:text="标签" />
5 设置点击事件,默认选中第一个
tagFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
@Override
public boolean onTagClick(View view, int position, FlowLayout parent) {
LogUtil.e("点击了tag:"+position);
return false;
}
});
tagFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
@Override
public void onSelected(Set<Integer> selectPosSet) {
LogUtil.e("选中了tag:"+selectPosSet); }
});
adapter.setSelectedList(0);//默认选中第一个
最新文章
- PHPer不能不看的50个细节!
- [Web API] Web API 2 深入系列(1) 路由
- ZBrush该如何通过结合KeyShot制作逼真玉佩
- Leetcode详解Maximum Sum Subarray
- java:[1,1] 需要class, interface或enum
- 怎么让LinearLayout充满ScrollView
- Authentication with SignalR and OAuth Bearer Token
- 【转载】free查看内存
- NOIP2015 子串 (DP+优化)
- GridView控件的光棒效应
- ocs添加仓库受限问题
- MBR区、DBR区、FAT区、DIR区和DATA区的区别
- 编译Uboot时提示error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
- 阿里巴巴Java规约插件试用
- YARN的笔记
- Windbg:通过vmware调试进行内核调试
- OpenEXR的读取机制
- SpringMVC学习笔记:单例与并发问题
- HBase写入性能改造(续)--MemStore、flush、compact参数调优及压缩卡的使用【转】
- [PyCharm] 设置自动启动时自动打开项目
热门文章
- [ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Cannot access nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public) in off
- mac chromedriver error
- vue项目1-pizza点餐系统6-路由精讲之复用router-view
- Python爬虫之urllib.parse详解
- Django之AJAX请求
- Django模型层1
- MongoDB与python 交互
- HMP许可更新
- 矩阵快速幂 求斐波那契第N项
- hdu 1505 单调栈升级版