-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hongyangAndroid
committed
Sep 10, 2015
1 parent
6237150
commit d4766a8
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,84 @@ | ||
# FlowLayout | ||
Android流式布局,支持单选、多选等,适合用于产品标签等。 | ||
|
||
|
||
##特色 | ||
* 以setAdapter形式注入数据 | ||
* 直接设置selector为background即可完成标签选则的切换,类似CheckBox | ||
* 支持控制选择的Tag数量,比如:单选、多选 | ||
* 支持setOnTagClickListener,当点击某个Tag回调 | ||
* 支持setOnSelectListener,当选择某个Tag后回调 | ||
* 支持adapter.notifyDataChanged | ||
* Activity重建(或者旋转)后,选择的状态自动保存 | ||
|
||
##效果图 | ||
|
||
<img src="flowlayout.gif" width="320px"/> | ||
|
||
## 用法 | ||
|
||
### 声明 | ||
布局文件中声明: | ||
|
||
```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的数量 | ||
`multi_suppout` 是否开启多选的支持,默认为true | ||
|
||
###设置数据 | ||
|
||
```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 | ||
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()); | ||
} | ||
}); | ||
``` | ||
选择多个标签时的回调。 | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters