[![Android Gems](http://www.android-gems.com/badge/hongyangAndroid/FlowLayout.svg?branch=master)](http://www.android-gems.com/lib/hongyangAndroid/FlowLayout)
# FlowLayout
Android流式布局,支持单选、多选等,适合用于产品标签等。
##特色
* 以setAdapter形式注入数据
* 直接设置selector为background即可完成标签选则的切换,类似CheckBox
* 支持控制选择的Tag数量,比如:单选、多选
* 支持setOnTagClickListener,当点击某个Tag回调
* 支持setOnSelectListener,当选择某个Tag后回调
* 支持adapter.notifyDataChanged
* Activity重建(或者旋转)后,选择的状态自动保存
##效果图
<img src="flowlayout_03.gif" width="320px"/>
<img src="sc.png" width="320px"/>
## 用法
```java
dependencies {
compile 'com.hyman:flowlayout-lib:1.1.2'
}
```
### 声明
布局文件中声明:
```java
<com.zhy.view.flowlayout.TagFlowLayout
android:id="@+id/id_flowlayout"
zhy:max_select="-1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp">
</com.zhy.view.flowlayout.TagFlowLayout>
```
支持属性:
`max_select`:-1为不限制选择数量,>=1的数字为控制选择tag的数量
支持通过state=checked来控制选中和取消,也可以自己在Adapter
的onSelected和unSelected中分别处理显示。
###设置数据
```java
mFlowLayout.setAdapter(new TagAdapter<String>(mVals)
{
@Override
public View getView(FlowLayout parent, int position, String s)
{
TextView tv = (TextView) mInflater.inflate(R.layout.tv,
mFlowLayout, false);
tv.setText(s);
return tv;
}
});
```
getView中回调,类似ListView等用法。
### 对于选中状态
```java
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/tag_select_textcolor"
android:drawable="@drawable/checked_bg"
android:state_checked="true"></item>
<item android:drawable="@drawable/normal_bg"></item>
</selector>
```
设置个background,上面一个状态为android:state_checked,另一个为正常。写写布局文件我都嫌慢,怎么能写一堆代码控制效果,设置改个效果,岂不是没时间dota了。
也可以不依赖state_checked,在下面的回调中自行设置:
```
#Adapter
@Override
public void onSelected(int position, View view) {
super.onSelected(position, view);
}
@Override
public void unSelected(int position, View view) {
super.unSelected(position, view);
}
```
###事件
```java
mFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener()
{
@Override
public boolean onTagClick(View view, int position, FlowLayout parent)
{
Toast.makeText(getActivity(), mVals[position], Toast.LENGTH_SHORT).show();
return true;
}
});
```
点击标签时的回调。
```java
mFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener()
{
@Override
public void onSelected(Set<Integer> selectPosSet)
{
getActivity().setTitle("choose:" + selectPosSet.toString());
}
});
```
选择多个标签时的回调。
##预先设置Item选中
```java
//预先设置选中
mAdapter.setSelectedList(1,3,5,7,8,9);
//获得所有选中的pos集合
flowLayout.getSelectedList();
```
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
标签控件 流式布局 实现多选 (1588个子文件)
flowlayout-lib-release.aar 12KB
flowlayout-lib-debug.aar 1KB
MediaSessionCompat.aidl 787B
ParcelableVolumeInfo.aidl 689B
PlaybackStateCompat.aidl 688B
MediaDescriptionCompat.aidl 683B
MediaMetadataCompat.aidl 680B
ResultReceiver.aidl 675B
RatingCompat.aidl 673B
resources-debug.ap_ 431KB
resources-debug-androidTest.ap_ 2KB
resources-debug-androidTest.ap_ 757B
flowlayout-debug.apk 1.73MB
gradlew.bat 2KB
fileSnapshots.bin 3.19MB
fileHashes.bin 293KB
taskArtifacts.bin 152KB
localClassSetAnalysis.bin 60KB
fileSnapshotsToTreeSnapshotsIndex.bin 56KB
localJarClasspathSnapshot.bin 23KB
localClassSetAnalysis.bin 21KB
localJarClasspathSnapshot.bin 18KB
R$styleable.class 38KB
R$styleable.class 30KB
R$style.class 23KB
R$style.class 23KB
R$styleable.class 22KB
R$style.class 22KB
R$attr.class 15KB
R$attr.class 13KB
R$attr.class 10KB
R$styleable.class 9KB
R$dimen.class 8KB
R$dimen.class 8KB
TagFlowLayout.class 6KB
R$id.class 6KB
R$drawable.class 6KB
R$drawable.class 6KB
FlowLayout.class 6KB
FlowLayout.class 6KB
FlowLayout.class 6KB
TagFlowLayout.class 6KB
TagFlowLayout.class 6KB
R$dimen.class 6KB
R$id.class 6KB
R$drawable.class 5KB
R$color.class 5KB
R$color.class 5KB
R$color.class 5KB
R$id.class 4KB
TagAdapter.class 4KB
TagAdapter.class 4KB
TagAdapter.class 4KB
R$layout.class 4KB
R$layout.class 3KB
SimpleFragment.class 3KB
R$layout.class 3KB
R$string.class 3KB
R$attr.class 3KB
R$string.class 3KB
R$string.class 2KB
SimpleFragment$2.class 2KB
TagView.class 1KB
TagView.class 1KB
TagView.class 1KB
SimpleFragment$3.class 1KB
TagFlowLayout$1.class 1KB
TagFlowLayout$1.class 1KB
TagFlowLayout$1.class 1KB
SimpleFragment$4.class 1KB
MutiActivity.class 1KB
SimpleFragment$1.class 1KB
R$anim.class 1KB
R$anim.class 1KB
R.class 1KB
R.class 1015B
BlankActivity.class 1015B
R.class 989B
BlankActivity$1.class 984B
R$styleable.class 887B
R$integer.class 845B
R$integer.class 833B
R$anim.class 813B
R$styleable.class 787B
BuildConfig.class 711B
R$bool.class 680B
R$dimen.class 664B
R$bool.class 662B
R$bool.class 650B
R$id.class 647B
R.class 645B
R$integer.class 611B
R$styleable.class 602B
R$dimen.class 599B
R$string.class 598B
R$styleable.class 596B
BuildConfig.class 591B
BuildConfig.class 591B
BuildConfig.class 591B
R.class 559B
共 1588 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16
资源评论
- mylihaihui2018-06-12挺好用的,确实是不错
程序员老林
- 粉丝: 10
- 资源: 44
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功