├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── dalong
│ │ └── flowlayoutdemo
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── dalong
│ │ │ └── flowlayoutdemo
│ │ │ ├── DLMainActivity.java
│ │ │ └── FlowEntity.java
│ └── res
│ │ ├── color
│ │ └── test_flowlayout_item_text_color.xml
│ │ ├── drawable
│ │ ├── bg_tag.xml
│ │ ├── flag_01.xml
│ │ ├── flow_item_bg_selector.xml
│ │ ├── flow_item_checked_bg.xml
│ │ ├── flow_item_unchecked_bg.xml
│ │ └── flow_item_unenable_bg.xml
│ │ ├── layout
│ │ └── activity_dlmain.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── dalong
│ └── flowlayout
│ └── ExampleUnitTest.java
├── build.gradle
├── flowlayout
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── dalong
│ │ └── flowlayout
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── dalong
│ │ │ └── flowlayout
│ │ │ ├── DLFlowLayout.java
│ │ │ └── Flow.java
│ └── res
│ │ ├── color
│ │ └── flowlayout_item_text_bg.xml
│ │ ├── drawable
│ │ ├── flowlayout_item_bg_selector.xml
│ │ ├── flowlayout_item_checked_bg.xml
│ │ ├── flowlayout_item_unchecked_bg.xml
│ │ └── flowlayout_item_unenable_bg.xml
│ │ ├── layout
│ │ ├── view_flow_item.xml
│ │ └── view_flow_layout.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── dimen.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── dalong
│ └── flowlayout
│ └── ExampleUnitTest.java
├── gif
├── select.gif
└── tag.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | FlowLayout
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # For most of the current demand flowlayout
2 |
3 | # 效果图
4 | 
5 |
6 | 
7 |
8 | ## 2.0.0 版本新增功能:
9 | 1、解决流布局显示问其题,如设置padding或者在其他布局中显示问题。
10 | 2、单选
11 | 3、多选 增加最大数量限制设置及回调。
12 | 4、支持选择和tag标签 tag标签不能点击选择只能显示查看
13 | 5、增加是否平均分配宽度 还是自适。
14 |
15 | # 如何使用
16 |
17 |
30 |
31 | # gradle使用
32 |
33 | compile 'com.dalong:flowlayout:2.0.0'
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion '25.0.0'
6 |
7 | defaultConfig {
8 | applicationId "com.dalong.flowlayoutdemo"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0.3"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | compile project(':flowlayout')
25 | // compile 'com.dalong:flowlayout:1.0.2'
26 | compile 'com.android.support:appcompat-v7:23.3.0'
27 | compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
28 | testCompile 'junit:junit:4.12'
29 | }
30 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /android/tools/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/dalong/flowlayoutdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.dalong.flowlayoutdemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dalong/flowlayoutdemo/DLMainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dalong.flowlayoutdemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Toast;
7 |
8 | import com.dalong.flowlayout.DLFlowLayout;
9 | import com.dalong.flowlayout.Flow;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 | import java.util.Random;
14 |
15 | /**
16 | * qianqian
17 | */
18 | public class DLMainActivity extends AppCompatActivity {
19 |
20 | private DLFlowLayout flowLayout;
21 | String[] texts = new String[]{
22 | "好的", "坏的", "不能理解的", "美好的一天",
23 | "你好", "是", "好", "名字", "姓名",
24 | "超级大坏蛋", "不", "就是你", "不是我"
25 | };
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_dlmain);
31 | initView();
32 | initListenr();
33 |
34 | }
35 |
36 | private void initView() {
37 | flowLayout = (DLFlowLayout) findViewById(R.id.flowlayout);
38 | flowLayout.setFlowData(getFlowData());
39 | flowLayout.setDefaultSelects(new int[]{});
40 | }
41 |
42 | private void initListenr() {
43 | flowLayout.setOnSelectListener(new DLFlowLayout.OnSelectListener() {
44 | @Override
45 | public void onSelect(int position) {
46 | Toast.makeText(DLMainActivity.this,"position:"+position,Toast.LENGTH_SHORT).show();
47 | }
48 |
49 | @Override
50 | public void onOutLimit() {
51 | Toast.makeText(DLMainActivity.this,"超出限制",Toast.LENGTH_SHORT).show();
52 | }
53 | });
54 | }
55 |
56 | public void doClick(View view) {
57 | int a = new Random().nextInt(texts.length);
58 | Flow mFlow = new FlowEntity(String.valueOf(a), texts[a]);
59 | flowLayout.addChildView(mFlow);
60 | }
61 |
62 | public void relayoutToCompress(View view) {
63 | flowLayout.relayoutToCompress();
64 | }
65 |
66 | public void select(View view) {
67 | List selectedIndexs = flowLayout.isSelectedIndexs();
68 | StringBuffer buffer=new StringBuffer();
69 | for (int i=0;i getFlowData() {
82 | List list = new ArrayList<>();
83 | for (int i = 0; i < texts.length; i++) {
84 | Flow mFlow = new FlowEntity((i + 1) + "", texts[i]);
85 | list.add(mFlow);
86 | }
87 | return list;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dalong/flowlayoutdemo/FlowEntity.java:
--------------------------------------------------------------------------------
1 | package com.dalong.flowlayoutdemo;
2 |
3 | import com.dalong.flowlayout.Flow;
4 |
5 | /**
6 | * Created by zhouweilong on 16/4/25.
7 | */
8 | public class FlowEntity extends Flow {
9 | public String id;
10 | public String name;
11 |
12 | public FlowEntity(String id, String name) {
13 | this.id = id;
14 | this.name = name;
15 | }
16 |
17 | public String getId() {
18 | return id;
19 | }
20 |
21 | public void setId(String id) {
22 | this.id = id;
23 | }
24 |
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public void setName(String name) {
30 | this.name = name;
31 | }
32 |
33 | @Override
34 | public String getFlowId() {
35 | return id;
36 | }
37 |
38 | @Override
39 | public String getFlowName() {
40 | return name;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/res/color/test_flowlayout_item_text_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_tag.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/flag_01.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/flow_item_bg_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/flow_item_checked_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/flow_item_unchecked_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/flow_item_unenable_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_dlmain.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
30 |
31 |
32 |
33 |
38 |
39 |
45 |
46 |
52 |
53 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/FlowLayout/d76e4bb2507e045773cb4914a25aa74d4bfb76df/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/FlowLayout/d76e4bb2507e045773cb4914a25aa74d4bfb76df/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/FlowLayout/d76e4bb2507e045773cb4914a25aa74d4bfb76df/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/FlowLayout/d76e4bb2507e045773cb4914a25aa74d4bfb76df/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/FlowLayout/d76e4bb2507e045773cb4914a25aa74d4bfb76df/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #303F9F
7 |
8 |
9 |
10 | #FF4081
11 | #22b3de
12 | #5e75d8
13 | #f55451
14 | #22b3de
15 |
16 |
17 | #ffffff
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 | 1dp
7 | 20dp
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FlowLayout
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/test/java/com/dalong/flowlayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dalong.flowlayoutdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 | classpath 'com.novoda:bintray-release:0.3.4'
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/flowlayout/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/flowlayout/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'//添加
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion '25.0.0'
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.3.0'
25 | }
26 |
27 | //添加
28 | publish {
29 | userOrg = 'dalong982242260'//bintray.com用户名
30 | groupId = 'com.dalong'//jcenter上的路径
31 | artifactId = 'flowlayout'//项目名称
32 | publishVersion = '2.0.0'//版本号
33 | desc = 'A flow layout for Android'//描述,不重要
34 | website = 'https://github.com/dalong982242260/FlowLayout'//网站,不重要
35 | }
36 |
--------------------------------------------------------------------------------
/flowlayout/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /android/tools/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/flowlayout/src/androidTest/java/com/dalong/flowlayout/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.dalong.flowlayoutdemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/flowlayout/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/flowlayout/src/main/java/com/dalong/flowlayout/DLFlowLayout.java:
--------------------------------------------------------------------------------
1 | package com.dalong.flowlayout;
2 |
3 | import android.content.Context;
4 | import android.content.res.ColorStateList;
5 | import android.content.res.TypedArray;
6 | import android.util.AttributeSet;
7 | import android.util.TypedValue;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.CheckBox;
12 | import android.widget.LinearLayout;
13 |
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 |
18 | /**
19 | * Created by dalong on 2017/5/31.
20 | */
21 |
22 | public class DLFlowLayout extends ViewGroup {
23 | // 可选择的
24 | private final static int STYPE_SELECT = 0;
25 | //便签 没有选中区分
26 | private final static int STYPE_TAG = 1;
27 | //每行的view列表
28 | private List> mViewLinesList = new ArrayList<>();
29 | //所有子view集合
30 | private List mChildList = new ArrayList<>();
31 | //每行的高
32 | private List mLineHeights = new ArrayList<>();
33 | private int usefulWidth;
34 | //是否单选
35 | private boolean mIsSingle = true;
36 | //是否平均
37 | private boolean mEqually = true;
38 | private ColorStateList mTextColor = getResources().getColorStateList(R.color.flowlayout_item_text_bg);//文字选择器
39 | //背景
40 | private int mBackground;
41 | //默认可选择的
42 | private int mStype = STYPE_SELECT;
43 | //文字的大小
44 | private float mTextSize;
45 | private Context mContext;
46 | //选择表示 默认是-1不选择
47 | private int mSelectPosition = -1;
48 | //选择最大值
49 | private int maxSelectNum = -1;
50 | //水平间距
51 | private int mHorizontalSpacing;
52 | //竖直间距
53 | private int mVerticalSpacing;
54 | private List mData = new ArrayList<>();
55 | //选择回调
56 | public OnSelectListener mOnSelectListener;
57 | //最大的item
58 | private int maxItemW;
59 |
60 | public DLFlowLayout(Context context) {
61 | this(context, null);
62 | }
63 |
64 | public DLFlowLayout(Context context, AttributeSet attrs) {
65 | this(context, attrs, 0);
66 | }
67 |
68 | public DLFlowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
69 | super(context, attrs, defStyleAttr);
70 | this.mContext = context;
71 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DLFlowLayout);
72 | mStype = typedArray.getInt(R.styleable.DLFlowLayout_DL_stype, STYPE_SELECT);
73 | mTextColor = typedArray.getColorStateList(R.styleable.DLFlowLayout_DL_textColor);
74 | mBackground = typedArray.getResourceId(R.styleable.DLFlowLayout_DL_flowBg, R.drawable.flowlayout_item_bg_selector);
75 | mTextSize = typedArray.getFloat(R.styleable.DLFlowLayout_DL_textSize, 14);
76 | mEqually = typedArray.getBoolean(R.styleable.DLFlowLayout_DL_equally, true);
77 | mIsSingle = typedArray.getBoolean(R.styleable.DLFlowLayout_DL_isSingle, true);
78 | maxSelectNum = typedArray.getInt(R.styleable.DLFlowLayout_DL_maxSelectNum, -1);
79 | mHorizontalSpacing = typedArray.getDimensionPixelSize(R.styleable.DLFlowLayout_DL_horizontalSpacing, 6);
80 | mVerticalSpacing = typedArray.getDimensionPixelSize(R.styleable.DLFlowLayout_DL_verticalSpacing, 6);
81 | typedArray.recycle();
82 | }
83 |
84 | @Override
85 | protected LayoutParams generateLayoutParams(LayoutParams p) {
86 | return new MarginLayoutParams(p);
87 | }
88 |
89 | @Override
90 | protected LayoutParams generateDefaultLayoutParams() {
91 | return new MarginLayoutParams(super.generateDefaultLayoutParams());
92 | }
93 |
94 | @Override
95 | public LayoutParams generateLayoutParams(AttributeSet attrs) {
96 | return new MarginLayoutParams(getContext(), attrs);
97 | }
98 |
99 | @Override
100 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
101 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
102 | //获取父容器DLFlowlayout设置测量模式和大小
103 | int iWidthMode = MeasureSpec.getMode(widthMeasureSpec);
104 | int iHeightMode = MeasureSpec.getMode(heightMeasureSpec);
105 | int iWidthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
106 | int iHeightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
107 |
108 | //获取控件的padding
109 | int mPaddingLeft = getPaddingLeft();
110 | int mPaddingRight = getPaddingRight();
111 | int mPaddingTop = getPaddingTop();
112 | int mPaddingBottom = getPaddingBottom();
113 |
114 | int iLineLeftRrightPadding = mPaddingLeft + mPaddingRight;
115 |
116 | //控件的宽高
117 | int measureWidth = iWidthSpecSize;
118 | int measureHeight = 0;
119 | //一行的宽高
120 | int iCurLineW = 0;
121 | int iCurLineH = 0;
122 |
123 | if (iWidthMode == MeasureSpec.EXACTLY && iHeightMode == MeasureSpec.EXACTLY) {
124 | measureWidth = iWidthSpecSize;
125 | measureHeight = iHeightSpecSize;
126 | } else {
127 | int iChildWidth;
128 | int iChildHeight;
129 | int childCount = getChildCount();
130 | List viewList = new ArrayList<>();
131 | for (int i = 0; i < childCount; i++) {
132 | View childView = getChildAt(i);
133 | if (mEqually) {
134 | resetItemWidth(childView, maxItemW);
135 | }
136 | measureChild(childView, widthMeasureSpec, heightMeasureSpec);
137 | MarginLayoutParams layoutParams = (MarginLayoutParams) childView.getLayoutParams();
138 | iChildWidth = childView.getMeasuredWidth() + layoutParams.leftMargin + layoutParams.rightMargin;
139 | iChildHeight = childView.getMeasuredHeight() + layoutParams.topMargin + layoutParams.bottomMargin;
140 | if (iCurLineW + iChildWidth + iLineLeftRrightPadding > iWidthSpecSize) {
141 | /**1、记录当前行的信息***/
142 | //记录当前行的最大宽度,高度叠加
143 | measureWidth = Math.max(measureWidth, iCurLineW);
144 | measureHeight += iCurLineH;
145 | //将当前行的viewList添加至总的行view集合中
146 | mViewLinesList.add(viewList);
147 | //将行高添加至总的行高list中
148 | mLineHeights.add(iCurLineH);
149 |
150 | /**2、记录新一行的信息***/
151 | //1、重新赋值新一行的宽、高
152 | iCurLineW = iChildWidth;
153 | iCurLineH = iChildHeight;
154 | //2、新建一行的viewlist,添加新一行的view
155 | viewList = new ArrayList();
156 | viewList.add(childView);
157 |
158 | } else {
159 |
160 | //记录每行的信息
161 | //1、行内宽度的叠加、高度比较
162 | iCurLineW += iChildWidth;
163 | iCurLineH = Math.max(iCurLineH, iChildHeight);
164 | // 2、添加至当前行的viewList中
165 | viewList.add(childView);
166 | }
167 | /*****3、如果正好是最后一行需要换行**********/
168 | if (i == childCount - 1) {
169 | measureWidth = Math.max(measureWidth, iCurLineW);
170 | measureHeight += iCurLineH;
171 | //将当前行的viewList添加至总的行view集合中
172 | mViewLinesList.add(viewList);
173 | //将行高添加至总的行高list中
174 | mLineHeights.add(iCurLineH);
175 | }
176 | }
177 | measureHeight = measureHeight + mPaddingTop + mPaddingBottom;
178 | }
179 | setMeasuredDimension(measureWidth, measureHeight);
180 | }
181 |
182 | @Override
183 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
184 | usefulWidth = r - l - getPaddingLeft() - getPaddingRight();
185 | int mPaddingLeft = getPaddingLeft();
186 | int mPaddingRight = getPaddingRight();
187 | int mPaddingTop = getPaddingTop();
188 |
189 | int left, top, right, bottom;
190 | int curTop = mPaddingTop;
191 | int curLeft = mEqually ? 0 : mPaddingLeft;
192 | int lineCount = mViewLinesList.size();
193 | int space = 0;
194 | if (mEqually) {
195 | if (mViewLinesList.size() > 0) {
196 | List viewList = mViewLinesList.get(0);
197 | int lineViewSize = viewList.size();
198 | space = (getWidth() - viewList.get(0).getMeasuredWidth() * lineViewSize) / (lineViewSize + 1);
199 | }
200 | }
201 | for (int i = 0; i < lineCount; i++) {
202 | if (mEqually) {
203 | List viewList = mViewLinesList.get(i);
204 | int lineViewSize = viewList.size();
205 | for (int j = 0; j < lineViewSize; j++) {
206 | View childView = viewList.get(j);
207 | MarginLayoutParams layoutParams = (MarginLayoutParams) childView.getLayoutParams();
208 | left = curLeft + space;
209 | top = curTop + layoutParams.topMargin;
210 | right = left + childView.getMeasuredWidth();
211 | bottom = top + childView.getMeasuredHeight();
212 | childView.layout(left, top, right, bottom);
213 | curLeft += childView.getMeasuredWidth() + space;
214 | }
215 | //重置 左面为mPaddingLeft top下一行叠加
216 | curLeft = mEqually ? 0 : mPaddingLeft;
217 | curTop += mLineHeights.get(i);
218 | } else {
219 | List viewList = mViewLinesList.get(i);
220 | int lineViewSize = viewList.size();
221 | for (int j = 0; j < lineViewSize; j++) {
222 | View childView = viewList.get(j);
223 | MarginLayoutParams layoutParams = (MarginLayoutParams) childView.getLayoutParams();
224 | left = curLeft + layoutParams.leftMargin;
225 | top = curTop + layoutParams.topMargin;
226 | right = left + childView.getMeasuredWidth();
227 | bottom = top + childView.getMeasuredHeight();
228 | childView.layout(left, top, right, bottom);
229 | curLeft += childView.getMeasuredWidth() + layoutParams.leftMargin + layoutParams.rightMargin;
230 | }
231 | //重置 左面为mPaddingLeft top下一行叠加
232 | curLeft = mPaddingLeft;
233 | curTop += mLineHeights.get(i);
234 | }
235 |
236 | }
237 | mViewLinesList.clear();
238 | mLineHeights.clear();
239 | }
240 |
241 |
242 | /**
243 | * 重新压缩布局 让空白控件尽量少
244 | */
245 | public void relayoutToCompress() {
246 | post(new Runnable() {
247 | @Override
248 | public void run() {
249 | compress();
250 | }
251 | });
252 | }
253 |
254 | private void compress() {
255 | int childCount = this.getChildCount();
256 | if (0 == childCount) {
257 | return;
258 | }
259 | int count = childCount;
260 | View[] childs = new View[count];
261 | int[] spaces = new int[count];
262 | int n = 0;
263 | for (int i = 0; i < childCount; i++) {
264 | View v = getChildAt(i);
265 | childs[n] = v;
266 | LayoutParams childLp = v.getLayoutParams();
267 | int childWidth = v.getMeasuredWidth();
268 | if (childLp instanceof MarginLayoutParams) {
269 | MarginLayoutParams mlp = (MarginLayoutParams) childLp;
270 | spaces[n] = mlp.leftMargin + childWidth + mlp.rightMargin;
271 | } else {
272 | spaces[n] = childWidth;
273 | }
274 | n++;
275 | }
276 | int[] compressSpaces = new int[count];
277 | for (int i = 0; i < count; i++) {
278 | compressSpaces[i] = spaces[i] > usefulWidth ? usefulWidth : spaces[i];
279 | }
280 | sortToCompress(childs, compressSpaces);
281 | this.removeAllViews();
282 |
283 | for (View v : mChildList) {
284 | ViewGroup parent = (ViewGroup) v.getParent();
285 | if (parent != null) {
286 | parent.removeAllViewsInLayout();
287 | }
288 | this.addView(v);
289 | }
290 | mChildList.clear();
291 | }
292 |
293 | /**
294 | * 排序
295 | *
296 | * @param childs
297 | * @param spaces
298 | */
299 | private void sortToCompress(View[] childs, int[] spaces) {
300 | int childCount = childs.length;
301 | int[][] table = new int[childCount + 1][usefulWidth + 1];
302 | for (int i = 0; i < childCount + 1; i++) {
303 | for (int j = 0; j < usefulWidth; j++) {
304 | table[i][j] = 0;
305 | }
306 | }
307 | boolean[] flag = new boolean[childCount];
308 | for (int i = 0; i < childCount; i++) {
309 | flag[i] = false;
310 | }
311 | for (int i = 1; i <= childCount; i++) {
312 | for (int j = spaces[i - 1]; j <= usefulWidth; j++) {
313 | table[i][j] = (table[i - 1][j] > table[i - 1][j - spaces[i - 1]] + spaces[i - 1]) ? table[i - 1][j] : table[i - 1][j - spaces[i - 1]] + spaces[i - 1];
314 | }
315 | }
316 | int v = usefulWidth;
317 | for (int i = childCount; i > 0 && v >= spaces[i - 1]; i--) {
318 | if (table[i][v] == table[i - 1][v - spaces[i - 1]] + spaces[i - 1]) {
319 | flag[i - 1] = true;
320 | v = v - spaces[i - 1];
321 | }
322 | }
323 | int rest = childCount;
324 | View[] restArray;
325 | int[] restSpaces;
326 | for (int i = 0; i < flag.length; i++) {
327 | if (flag[i] == true) {
328 | mChildList.add(childs[i]);
329 | rest--;
330 | }
331 | }
332 |
333 | if (0 == rest) {
334 | return;
335 | }
336 | restArray = new View[rest];
337 | restSpaces = new int[rest];
338 | int index = 0;
339 | for (int i = 0; i < flag.length; i++) {
340 | if (flag[i] == false) {
341 | restArray[index] = childs[i];
342 | restSpaces[index] = spaces[i];
343 | index++;
344 | }
345 | }
346 | table = null;
347 | childs = null;
348 | flag = null;
349 | sortToCompress(restArray, restSpaces);
350 | }
351 |
352 | /**
353 | * 设置数据
354 | *
355 | * @param data 数据
356 | */
357 | public void setFlowData(List data) {
358 | this.mData = data;
359 | post(new Runnable() {
360 | @Override
361 | public void run() {
362 | removeAllViews();
363 | addViews(mData);
364 | postInvalidate();
365 | }
366 | });
367 |
368 | }
369 |
370 |
371 | /**
372 | * add View
373 | *
374 | * @param mData
375 | */
376 | private void addViews(List mData) {
377 | for (int i = 0; i < mData.size(); i++) {
378 | addChildView(mData.get(i));
379 | }
380 | if (mStype != STYPE_SELECT) {
381 | setAllUnEnable();
382 | }
383 | }
384 |
385 | /**
386 | * 添加view
387 | *
388 | * @param flow 数据
389 | */
390 | public void addChildView(Flow flow) {
391 | View itemView = LayoutInflater.from(mContext).inflate(R.layout.view_flow_item, null);
392 | LinearLayout itemViewRoot = (LinearLayout) itemView.findViewById(R.id.view_flow_item);
393 | CheckBox chk = (CheckBox) itemView.findViewById(R.id.single_select_chk);
394 | chk.setOnClickListener(new OnItemClickEvent());
395 | chk.setText(flow.getFlowName());
396 | chk.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSize);
397 | if (mTextColor != null) chk.setTextColor(mTextColor);
398 | chk.setBackgroundResource(mBackground);
399 | chk.setTag(mChildList == null ? 0 : mChildList.size());
400 | setUnChecked(chk);
401 | // 测量最长的一个条目的位置
402 | measureView(itemView);
403 | int width = itemView.getMeasuredWidth();
404 | MarginLayoutParams lp = new MarginLayoutParams(width, LayoutParams.MATCH_PARENT);
405 | lp.setMargins(dip2px(getContext(), mHorizontalSpacing / 2), dip2px(getContext(), mVerticalSpacing / 2),
406 | dip2px(getContext(), mHorizontalSpacing / 2), dip2px(getContext(), mVerticalSpacing / 2));
407 | itemViewRoot.setLayoutParams(lp);
408 | // 获取最长的条目长度 (比较后选择最大的一个单选框)
409 | if (width > maxItemW) {
410 | maxItemW = width;
411 | }
412 | mChildList.add(itemView);
413 | addView(itemView);
414 |
415 | if (mStype != STYPE_SELECT) {
416 | setUnRnable(itemView);
417 | }
418 |
419 | }
420 |
421 |
422 | /**
423 | * 重新设置条目宽度
424 | */
425 | private void resetItemWidth(View itemView, int itemW) {
426 | LinearLayout itemViewRoot = (LinearLayout) itemView
427 | .findViewById(R.id.view_flow_item);
428 | MarginLayoutParams lp = new MarginLayoutParams(itemW, LayoutParams.MATCH_PARENT);
429 | lp.setMargins(dip2px(getContext(), mHorizontalSpacing / 2), dip2px(getContext(), mVerticalSpacing / 2),
430 | dip2px(getContext(), mHorizontalSpacing / 2), dip2px(getContext(), mVerticalSpacing / 2));
431 | itemViewRoot.setLayoutParams(lp);
432 | }
433 |
434 | /**
435 | * 测量一个单选按钮的长度
436 | * @param v view
437 | *
438 | */
439 | public void measureView(View v) {
440 | if (v == null) {
441 | return;
442 | }
443 | int w = MeasureSpec.makeMeasureSpec(0,
444 | MeasureSpec.UNSPECIFIED);
445 | int h = MeasureSpec.makeMeasureSpec(0,
446 | MeasureSpec.UNSPECIFIED);
447 |
448 | v.measure(w, h);
449 | }
450 |
451 | /**
452 | * (点击事件)
453 | * 条目CheckBox的点击事件
454 | */
455 | private class OnItemClickEvent implements OnClickListener {
456 | @Override
457 | public void onClick(View v) {
458 | CheckBox chk = (CheckBox) v;
459 | if (chk.isChecked()) {
460 | mSelectPosition = (Integer) chk.getTag();
461 | if (maxSelectNum != -1 && !mIsSingle && isSelectedIndexs().size() > maxSelectNum) {
462 | setUnChecked(chk);
463 | if (mOnSelectListener != null) {
464 | mOnSelectListener.onOutLimit();// 超出限制
465 | }
466 | return;
467 | }
468 | notifyAllItemView(mSelectPosition);
469 | } else {
470 | setUnChecked(chk);
471 | mSelectPosition = -1;
472 | }
473 | ///只要使用这个回调就知道选中的是哪个了 我靠
474 | if (mOnSelectListener != null) {
475 | mOnSelectListener.onSelect(mSelectPosition);
476 | }
477 |
478 |
479 | }
480 | }
481 |
482 |
483 | /**
484 | * 设置默认选中项 name
485 | *
486 | * @param selectName 选中的name
487 | */
488 | public void setDefaultSelectName(String selectName) {
489 | for (int i = 0; i < mData.size(); i++) {
490 | Flow propertyValuesJson = mData.get(i);
491 | if (propertyValuesJson.getFlowName().equals(selectName)) {
492 | notifyAllItemView(i);
493 | return;
494 | }
495 |
496 | }
497 |
498 | }
499 |
500 | /**
501 | * 设置默认选中项 id
502 | *
503 | * @param selectId 要设置选中的id
504 | */
505 | public void setDefaultSelectId(String selectId) {
506 | for (int i = 0; i < mData.size(); i++) {
507 | Flow propertyValuesJson = mData.get(i);
508 | if (propertyValuesJson.getFlowId().equals(selectId)) {
509 | notifyAllItemView(i);
510 | return;
511 | }
512 | }
513 |
514 | }
515 |
516 | /**
517 | * 设置默认选中项
518 | *
519 | * @param select 设置默认选中的index
520 | */
521 | public void setDefaultSelect(int select) {
522 | notifyAllItemView(select);
523 | }
524 |
525 | public void setDefaultSelects(int[] select) {
526 | for (int i = 0; i < select.length; i++) {
527 | notifyAllItemView(select[i]);
528 | }
529 |
530 | }
531 |
532 | /**
533 | * 刷新数据
534 | *
535 | * @param mSelectPosition 选中
536 | */
537 | private void notifyAllItemView(int mSelectPosition) {
538 |
539 | for (int i = 0; i < getChildCount(); i++) {
540 | CheckBox chk = (CheckBox) getChildAt(i).findViewById(R.id.single_select_chk);
541 | int tag = (Integer) chk.getTag();
542 | //选中状态 单选
543 | if (mSelectPosition >= 0) {
544 | if (chk.isEnabled()) {
545 | if (tag == mSelectPosition) {
546 | this.mSelectPosition = mSelectPosition;
547 | setChecked(chk);
548 | } else {
549 | if (mIsSingle) {
550 | setUnChecked(chk);
551 | }
552 | }
553 | }
554 |
555 | }
556 |
557 | }
558 | }
559 |
560 | /**
561 | * 设置所有可点击
562 | */
563 | public void setAllEnable() {
564 | for (int i = 0; i < getChildCount(); i++) {
565 | CheckBox chk = (CheckBox) getChildAt(i).findViewById(R.id.single_select_chk);
566 | int tag = (Integer) chk.getTag();
567 | setEnabled(chk);
568 | if (tag == mSelectPosition) {
569 | setChecked(chk);
570 | } else {
571 | setUnChecked(chk);
572 | }
573 | }
574 | }
575 |
576 | /**
577 | * 设置不可点击项
578 | * @param position 位置
579 | */
580 | public void setUnEnable(int position) {
581 | for (int i = 0; i < getChildCount(); i++) {
582 | CheckBox chk = (CheckBox) getChildAt(i).findViewById(R.id.single_select_chk);
583 | int tag = (Integer) chk.getTag();
584 | if (tag == position)
585 | setUnEnabled(chk);
586 | }
587 | }
588 |
589 | /**
590 | * 设置所有不可点击
591 | */
592 | public void setAllUnEnable() {
593 | for (View itemView : mChildList) {
594 | setUnRnable(itemView);
595 | }
596 | }
597 |
598 | /**
599 | * 设置不可点击
600 | *
601 | * @param view 子view
602 | */
603 | public void setUnRnable(View view) {
604 | CheckBox chk = (CheckBox) view.findViewById(R.id.single_select_chk);
605 | setUnEnabled(chk);
606 | }
607 |
608 | /**
609 | * 获取是否被选择
610 | *
611 | * @return 是否被选择了
612 | */
613 | public boolean isSelectPosition() {
614 | for (int i = 0; i < getChildCount(); i++) {
615 | CheckBox chk = (CheckBox) getChildAt(i).findViewById(R.id.single_select_chk);
616 | if (chk.isChecked())
617 | return true;
618 | }
619 | return false;
620 | }
621 |
622 | /**
623 | * 获取选择的那个index(单选的时候可以直接用这个方法,如果的多选你用这个方法就会默认拿到第一个)
624 | *
625 | * @return 返回选中的集合
626 | */
627 | public int isSelectedIndex() {
628 | for (int i = 0; i < getChildCount(); i++) {
629 | CheckBox chk = (CheckBox) getChildAt(i).findViewById(R.id.single_select_chk);
630 | if (chk.isChecked())
631 | return i;
632 | }
633 | return -1;
634 | }
635 |
636 | /**
637 | * 获取选择的集合(多选)
638 | * @return 返回选中的index集合
639 | */
640 | public List isSelectedIndexs() {
641 | List mList = new ArrayList<>();
642 | for (int i = 0; i < getChildCount(); i++) {
643 | CheckBox chk = (CheckBox) getChildAt(i).findViewById(R.id.single_select_chk);
644 | if (chk.isChecked()) {
645 | mList.add(i);
646 | }
647 | }
648 | return mList;
649 | }
650 |
651 | /**
652 | * 设置还没有选择的样式
653 | *
654 | * @param view 子view
655 | */
656 | private void setUnChecked(CheckBox view) {
657 | view.setChecked(false);
658 | }
659 |
660 | /**
661 | * 设置被选择的样式
662 | *
663 | * @param view checkbox
664 | */
665 | private void setChecked(CheckBox view) {
666 | view.setChecked(true);
667 | }
668 |
669 | /**
670 | * 设置被设置能点击的样式
671 | *
672 | * @param view checkbox
673 | */
674 | private void setEnabled(CheckBox view) {
675 | view.setEnabled(true);
676 | }
677 |
678 | /**
679 | * 设置不能被点击的样式
680 | *
681 | * @param view checkbox
682 | */
683 | private void setUnEnabled(CheckBox view) {
684 | view.setEnabled(false);
685 | }
686 |
687 |
688 | /**
689 | * 描述:dip转换为px
690 | *
691 | * @param context 上下文
692 | * @param dipValue dip值
693 | * @return px值
694 | */
695 | public int dip2px(Context context, float dipValue) {
696 | final float scale = context.getResources().getDisplayMetrics().density;
697 | return (int) (dipValue * scale + 0.5f);
698 | }
699 |
700 |
701 | /**
702 | * 接口
703 | *
704 | * @author zhouweilong
705 | */
706 | public interface OnSelectListener {
707 | void onSelect(int position);
708 |
709 | void onOutLimit();//超出限制数量
710 | }
711 |
712 | /**
713 | * 实现接口回调
714 | *
715 | * @param l 接口
716 | */
717 | public void setOnSelectListener(OnSelectListener l) {
718 | this.mOnSelectListener = l;
719 | }
720 | }
721 |
--------------------------------------------------------------------------------
/flowlayout/src/main/java/com/dalong/flowlayout/Flow.java:
--------------------------------------------------------------------------------
1 | package com.dalong.flowlayout;
2 |
3 | /**
4 | * Created by zhouweilong on 16/4/22.
5 | */
6 | public class Flow {
7 |
8 | public String flowId;
9 | public String flowName;
10 |
11 | public String getFlowId() {
12 | return flowId;
13 | }
14 |
15 | public void setFlowId(String flowId) {
16 | this.flowId = flowId;
17 | }
18 |
19 | public String getFlowName() {
20 | return flowName;
21 | }
22 |
23 | public void setFlowName(String flowName) {
24 | this.flowName = flowName;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/color/flowlayout_item_text_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/drawable/flowlayout_item_bg_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/drawable/flowlayout_item_checked_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/drawable/flowlayout_item_unchecked_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/drawable/flowlayout_item_unenable_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/layout/view_flow_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
23 |
24 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/layout/view_flow_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | #FF4081
6 | #e3e3e3
7 |
8 | #57609e
9 | #f2f5f9
10 | #999999
11 |
12 | #8d8ea3
13 | #ffffff
14 |
15 | #3F51B5
16 | #303F9F
17 | #FF4081
18 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/values/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1dip
5 |
--------------------------------------------------------------------------------
/flowlayout/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FlowLayout
3 |
4 |
--------------------------------------------------------------------------------
/flowlayout/src/test/java/com/dalong/flowlayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dalong.flowlayout;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/gif/select.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/FlowLayout/d76e4bb2507e045773cb4914a25aa74d4bfb76df/gif/select.gif
--------------------------------------------------------------------------------
/gif/tag.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/FlowLayout/d76e4bb2507e045773cb4914a25aa74d4bfb76df/gif/tag.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/FlowLayout/d76e4bb2507e045773cb4914a25aa74d4bfb76df/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 31 19:17:35 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':flowlayout'
2 |
--------------------------------------------------------------------------------