Skip to content

Commit

Permalink
完善文档
Browse files Browse the repository at this point in the history
  • Loading branch information
hongyangAndroid committed Sep 10, 2015
1 parent 6237150 commit d4766a8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions README.md
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());
}
});
```
选择多个标签时的回调。


Binary file added flowLayout.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState)

mFlowLayout.setAdapter(new TagAdapter<String>(mVals)
{

@Override
public View getView(FlowLayout parent, int position, String s)
{
Expand Down

0 comments on commit d4766a8

Please sign in to comment.