├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── cornflower1991 │ │ └── flowlayout │ │ └── ExampleInstrumentationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── cornflower1991 │ │ │ └── flowlayout │ │ │ ├── DemoActivity.java │ │ │ ├── TagAdapter.java │ │ │ └── widget │ │ │ ├── FlowTagLayout.java │ │ │ ├── OnInitSelectedPosition.java │ │ │ ├── OnTagClickListener.java │ │ │ └── OnTagSelectListener.java │ └── res │ │ ├── drawable │ │ └── blue_rect_round_bg.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── tag_item.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 │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── cornflower1991 │ └── flowlayout │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images ├── 1.png ├── 2.png ├── 3.png ├── 4.png └── 5.png └── 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/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 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | Android API 19 Platform 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Android流式布局,支持单选、多选等,适合用于产品标签等,可以自定义标签颜色,标签大小,标签距离。 2 | 3 | #特色 4 | ####可以单选多选,使用方便 5 | ####可以自定义标签颜色,标签大小,标签距离 6 | ####以setAdapter形式注入数据 7 | ####直接设置selector为background即可完成标签选则的切换,类似CheckBox 8 | ####支持控制选择的Tag数量,比如:单选、多选 9 | ####支持setOnTagClickListener,当点击某个Tag回调 10 | ####支持setOnSelectListener,当选择某个Tag后回调 11 | ####支持adapter.notifyDataChanged 12 | ####Activity重建(或者旋转)后,选择的状态自动保存 13 | 14 | 15 | #效果图 16 | ##单选时 17 | ![image](https://github.com/qiushi123/FlowLayout-master/blob/master/images/2.png?raw=true) 18 | 19 | ##多选时 20 | ![image](https://github.com/qiushi123/FlowLayout-master/blob/master/images/3.png?raw=true) 21 | 22 | 23 | 24 | #使用步骤 25 | ##1,将项目里的类复制到你的项目中(这是源码奥,可以自己根据需求自己改,比导入类库灵活) 26 | ![image](https://github.com/qiushi123/FlowLayout-master/blob/master/images/4.png?raw=true) 27 | ##2,布局文件中声明: 28 | ![image](https://github.com/qiushi123/FlowLayout-master/blob/master/images/5.png?raw=true) 29 | 30 | ##3,常用设置(单选,多选,仅仅点击,默认选中项等) 31 | //这里FLOW_TAG_CHECKED_SINGLE是单选,FLOW_TAG_CHECKED_MULTI多选,默认是仅仅点击 32 | mSizeFlowTagLayout.setTagCheckedMode(FlowTagLayout.FLOW_TAG_CHECKED_SINGLE); 33 | 34 | mSizeTagAdapter.setSelected(4);//默认选择第四个 35 | 36 | 37 | ##4,事件 38 | 4-1选中事件 39 | mSizeFlowTagLayout.setOnTagSelectListener(new OnTagSelectListener() { 40 | @Override 41 | public void onItemSelect(FlowTagLayout parent, int position, List selectedList) { 42 | if (selectedList != null && selectedList.size() > 0) { 43 | StringBuilder sb = new StringBuilder(); 44 | for (int i : selectedList) { 45 | //这里的parent.getAdapter().getItem(i)用来获取选中的标签的数据 46 | sb.append(parent.getAdapter().getItem(i)); 47 | sb.append(":"); 48 | } 49 | Snackbar.make(parent, position + "恭喜你" + sb.toString(), Snackbar.LENGTH_LONG) 50 | .setAction("Action", null).show(); 51 | } else { 52 | Snackbar.make(parent, "没有选择标签", Snackbar.LENGTH_LONG) 53 | .setAction("Action", null).show(); 54 | } 55 | } 56 | }); 57 | 58 | 4-2点击事件 59 | mColorFlowTagLayout.setOnTagClickListener(new OnTagClickListener() { 60 | @Override 61 | public void onItemClick(FlowTagLayout parent, View view, int position) { 62 | Snackbar.make(view, "点击了标签"+position, Snackbar.LENGTH_LONG) 63 | .setAction("Action", null).show(); 64 | } 65 | }); 66 | 67 | ##5,可以自定义标签大小距离等属性 68 | @Override 69 | public View getView(int position, View convertView, ViewGroup parent) { 70 | //这里大家熟悉吧,就是使用listview的adapter,这里的布局就是标签的布局,可以自己定义 71 | View view = LayoutInflater.from(mContext).inflate(R.layout.tag_item, null); 72 | if (t instanceof String) { 73 | textView.setText((String) t); 74 | } 75 | return view; 76 | } 77 | 78 | 上面tag_item的布局(是不是感觉自定义定义标签so easy) 79 | 80 | 85 | 97 | 98 | 99 | ##6,自定义标签选中颜色, 100 | 上面5中的tv_tag的background属性,可以自己定义选中颜色 101 | 102 | 103 | 我的个人博客 104 | http://blog.csdn.net/qiushi_1990 105 | 106 | 107 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | defaultConfig { 7 | applicationId "com.cornflower1991.flowlayout" 8 | minSdkVersion 15 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 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(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:design:23.1.0' 25 | compile 'com.android.support:appcompat-v7:23.1.0' 26 | testCompile 'junit:junit:4.12' 27 | 28 | } 29 | -------------------------------------------------------------------------------- /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 C:\Users\appchina\AppData\Local\Android\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/cornflower1991/flowlayout/ExampleInstrumentationTest.java: -------------------------------------------------------------------------------- 1 | package com.cornflower1991.flowlayout; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.filters.MediumTest; 6 | import android.support.test.runner.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | 12 | import static org.junit.Assert.*; 13 | 14 | /** 15 | * Instrumentation test, which will execute on an Android device. 16 | * 17 | * @see Testing documentation 18 | */ 19 | @MediumTest 20 | @RunWith(AndroidJUnit4.class) 21 | public class ExampleInstrumentationTest { 22 | @Test 23 | public void useAppContext() throws Exception { 24 | // Context of the app under test. 25 | Context appContext = InstrumentationRegistry.getTargetContext(); 26 | 27 | assertEquals("com.cornflower1991.flowlayout", appContext.getPackageName()); 28 | } 29 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 10 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/cornflower1991/flowlayout/DemoActivity.java: -------------------------------------------------------------------------------- 1 | package com.cornflower1991.flowlayout; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.FloatingActionButton; 5 | import android.support.design.widget.Snackbar; 6 | import android.support.v7.app.ActionBar; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.Toolbar; 9 | import android.view.View; 10 | import android.widget.TextView; 11 | 12 | import com.cornflower1991.flowlayout.widget.FlowTagLayout; 13 | import com.cornflower1991.flowlayout.widget.OnTagClickListener; 14 | import com.cornflower1991.flowlayout.widget.OnTagSelectListener; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * Created by yexiuliang on 2016/7/11. 21 | */ 22 | 23 | public class DemoActivity extends AppCompatActivity { 24 | 25 | private FlowTagLayout mColorFlowTagLayout; 26 | private FlowTagLayout mSizeFlowTagLayout; 27 | private FlowTagLayout mMobileFlowTagLayout; 28 | private TagAdapter mSizeTagAdapter; 29 | private TagAdapter mColorTagAdapter; 30 | private TagAdapter mMobileTagAdapter; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 37 | // toolbar.setTitle(""); 38 | TextView textView = (TextView) findViewById(R.id.toolbar_title); 39 | textView.setText("流式标签可单选多选"); 40 | 41 | setSupportActionBar(toolbar); 42 | ActionBar actionBar = getSupportActionBar(); 43 | if (actionBar != null) { 44 | actionBar.setDisplayHomeAsUpEnabled(true); 45 | actionBar.setDisplayShowTitleEnabled(false); 46 | } 47 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { 48 | @Override 49 | public void onClick(View v) { 50 | onBackPressed(); 51 | } 52 | }); 53 | 54 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 55 | fab.setOnClickListener(new View.OnClickListener() { 56 | @Override 57 | public void onClick(View view) { 58 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 59 | .setAction("Action", null).show(); 60 | } 61 | }); 62 | 63 | // 点击 64 | mColorFlowTagLayout = (FlowTagLayout) findViewById(R.id.single_click_flow_layout); 65 | // 单选 66 | mSizeFlowTagLayout = (FlowTagLayout) findViewById(R.id.single_choose_flow_layout); 67 | // 多选 68 | mMobileFlowTagLayout = (FlowTagLayout) findViewById(R.id.multi_select_flow_layout); 69 | 70 | //点击 71 | mColorTagAdapter = new TagAdapter<>(this); 72 | mColorFlowTagLayout.setAdapter(mColorTagAdapter); 73 | mColorFlowTagLayout.setOnTagClickListener(new OnTagClickListener() { 74 | @Override 75 | public void onItemClick(FlowTagLayout parent, View view, int position) { 76 | Snackbar.make(view, "点击了标签"+position, Snackbar.LENGTH_LONG) 77 | .setAction("Action", null).show(); 78 | } 79 | }); 80 | 81 | //单选 82 | mSizeTagAdapter = new TagAdapter<>(this); 83 | mSizeTagAdapter.setSelected(4);//默认选择第四个 84 | //这里FLOW_TAG_CHECKED_SINGLE是单选,FLOW_TAG_CHECKED_MULTI多选 85 | mSizeFlowTagLayout.setTagCheckedMode(FlowTagLayout.FLOW_TAG_CHECKED_SINGLE); 86 | mSizeFlowTagLayout.setAdapter(mSizeTagAdapter); 87 | mSizeFlowTagLayout.setOnTagSelectListener(new OnTagSelectListener() { 88 | @Override 89 | public void onItemSelect(FlowTagLayout parent, int position, List selectedList) { 90 | if (selectedList != null && selectedList.size() > 0) { 91 | StringBuilder sb = new StringBuilder(); 92 | for (int i : selectedList) { 93 | sb.append(parent.getAdapter().getItem(i)); 94 | sb.append(":"); 95 | } 96 | Snackbar.make(parent, position + "恭喜你" + sb.toString(), Snackbar.LENGTH_LONG) 97 | .setAction("Action", null).show(); 98 | } else { 99 | Snackbar.make(parent, "没有选择标签", Snackbar.LENGTH_LONG) 100 | .setAction("Action", null).show(); 101 | } 102 | } 103 | }); 104 | 105 | //多选 106 | mMobileTagAdapter = new TagAdapter<>(this); 107 | mMobileFlowTagLayout.setTagCheckedMode(FlowTagLayout.FLOW_TAG_CHECKED_MULTI); 108 | mMobileFlowTagLayout.setAdapter(mMobileTagAdapter); 109 | mMobileFlowTagLayout.setOnTagSelectListener(new OnTagSelectListener() { 110 | @Override 111 | public void onItemSelect(FlowTagLayout parent, int positon, List selectedList) { 112 | if (selectedList != null && selectedList.size() > 0) { 113 | StringBuilder sb = new StringBuilder(); 114 | 115 | for (int i : selectedList) { 116 | sb.append(parent.getAdapter().getItem(i)); 117 | sb.append(":"); 118 | } 119 | Snackbar.make(parent, "O(∩_∩)O哈哈哈~:" + sb.toString(), Snackbar.LENGTH_LONG) 120 | .setAction("Action", null).show(); 121 | } else { 122 | Snackbar.make(parent, "没有选择标签", Snackbar.LENGTH_LONG) 123 | .setAction("Action", null).show(); 124 | } 125 | } 126 | }); 127 | 128 | initColorData(); 129 | 130 | initSizeData(); 131 | 132 | initMobileData(); 133 | } 134 | 135 | private void initMobileData() { 136 | List dataSource = new ArrayList<>(); 137 | for (int i = 0; i < 10; i++) { 138 | dataSource.add("多选*-* " + i); 139 | 140 | } 141 | mMobileTagAdapter.onlyAddAll(dataSource); 142 | } 143 | 144 | private void initColorData() { 145 | List dataSource = new ArrayList<>(); 146 | for (int i = 0; i < 10; i++) { 147 | dataSource.add("单击!+! " + i); 148 | 149 | } 150 | mColorTagAdapter.onlyAddAll(dataSource); 151 | } 152 | 153 | /** 154 | * 初始化数据 155 | */ 156 | private void initSizeData() { 157 | List dataSource = new ArrayList<>(); 158 | for (int i = 0; i < 10; i++) { 159 | dataSource.add("单选^-^ " + i); 160 | 161 | } 162 | mSizeTagAdapter.onlyAddAll(dataSource); 163 | } 164 | 165 | // @Override 166 | // public boolean onCreateOptionsMenu(Menu menu) { 167 | // // Inflate the menu; this adds items to the action bar if it is present. 168 | // getMenuInflater().inflate(R.menu.menu_main, menu); 169 | // return true; 170 | // } 171 | // 172 | // @Override 173 | // public boolean onOptionsItemSelected(MenuItem item) { 174 | // // Handle action bar item clicks here. The action bar will 175 | // // automatically handle clicks on the Home/Up button, so long 176 | // // as you specify a parent activity in AndroidManifest.xml. 177 | // int id = item.getItemId(); 178 | // 179 | // //noinspection SimplifiableIfStatement 180 | // if (id == R.id.action_settings) { 181 | // return true; 182 | // } 183 | // 184 | // return super.onOptionsItemSelected(item); 185 | // } 186 | 187 | } 188 | -------------------------------------------------------------------------------- /app/src/main/java/com/cornflower1991/flowlayout/TagAdapter.java: -------------------------------------------------------------------------------- 1 | package com.cornflower1991.flowlayout; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.TextView; 9 | 10 | 11 | import com.cornflower1991.flowlayout.widget.OnInitSelectedPosition; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by HanHailong on 15/10/19. 18 | */ 19 | public class TagAdapter extends BaseAdapter implements OnInitSelectedPosition { 20 | 21 | private final Context mContext; 22 | private final List mDataList; 23 | 24 | public TagAdapter(Context context) { 25 | this.mContext = context; 26 | mDataList = new ArrayList<>(); 27 | } 28 | 29 | @Override 30 | public int getCount() { 31 | return mDataList.size(); 32 | } 33 | 34 | @Override 35 | public Object getItem(int position) { 36 | return mDataList.get(position); 37 | } 38 | 39 | @Override 40 | public long getItemId(int position) { 41 | return position; 42 | } 43 | 44 | @Override 45 | public View getView(int position, View convertView, ViewGroup parent) { 46 | 47 | View view = LayoutInflater.from(mContext).inflate(R.layout.tag_item, null); 48 | 49 | TextView textView = (TextView) view.findViewById(R.id.tv_tag); 50 | T t = mDataList.get(position); 51 | 52 | if (t instanceof String) { 53 | textView.setText((String) t); 54 | } 55 | return view; 56 | } 57 | 58 | public void onlyAddAll(List datas) { 59 | mDataList.addAll(datas); 60 | notifyDataSetChanged(); 61 | } 62 | 63 | public void clearAndAddAll(List datas) { 64 | mDataList.clear(); 65 | onlyAddAll(datas); 66 | } 67 | 68 | public int position; 69 | public void setSelected(int p) { 70 | position=p; 71 | } 72 | 73 | @Override 74 | public boolean isSelectedPosition(int poi) { 75 | if (poi == position) { 76 | return true; 77 | } 78 | return false; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/com/cornflower1991/flowlayout/widget/FlowTagLayout.java: -------------------------------------------------------------------------------- 1 | package com.cornflower1991.flowlayout.widget; 2 | 3 | import android.content.Context; 4 | import android.database.DataSetObserver; 5 | import android.util.AttributeSet; 6 | import android.util.SparseBooleanArray; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ListAdapter; 10 | 11 | import java.util.ArrayList; 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | /** 16 | * 流式标签布局 17 | * 原理:重写{@link ViewGroup#onMeasure(int, int)} 18 | * 和{@link ViewGroup#onLayout(boolean, int, int, int, int)}方法 19 | *

20 | * Created by yexiuliang on 2016/7/11. 21 | */ 22 | 23 | public class FlowTagLayout extends ViewGroup { 24 | /** 25 | * FlowLayout not support checked 26 | */ 27 | public static final int FLOW_TAG_CHECKED_NONE = 0;//只点击不选择 28 | /** 29 | * FlowLayout support single-select 30 | */ 31 | public static final int FLOW_TAG_CHECKED_SINGLE = 1;//单选 32 | /** 33 | * FlowLayout support multi-select 34 | */ 35 | public static final int FLOW_TAG_CHECKED_MULTI = 2;//多选 36 | 37 | /** 38 | * Should be used by subclasses to listen to changes in the dataset 39 | */ 40 | AdapterDataSetObserver mDataSetObserver; 41 | 42 | /** 43 | * The adapter containing the data to be displayed by this view 44 | */ 45 | ListAdapter mAdapter; 46 | 47 | /** 48 | * the tag click event callback 49 | */ 50 | OnTagClickListener mOnTagClickListener; 51 | 52 | /** 53 | * the tag select event callback 54 | */ 55 | OnTagSelectListener mOnTagSelectListener; 56 | 57 | /** 58 | * 标签流式布局选中模式,默认是不支持选中的 59 | */ 60 | private int mTagCheckMode = FLOW_TAG_CHECKED_NONE; 61 | 62 | /** 63 | * 存储选中的tag 64 | */ 65 | private SparseBooleanArray mCheckedTagArray = new SparseBooleanArray(); 66 | /** 67 | * 子View的宽度,如果为0 则为warp_content 68 | */ 69 | private int mWidth; 70 | 71 | 72 | public FlowTagLayout(Context context) { 73 | super(context); 74 | 75 | } 76 | 77 | public FlowTagLayout(Context context, AttributeSet attrs) { 78 | super(context, attrs); 79 | 80 | } 81 | 82 | public FlowTagLayout(Context context, AttributeSet attrs, int defStyleAttr) { 83 | super(context, attrs, defStyleAttr); 84 | 85 | } 86 | 87 | 88 | @Override 89 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 90 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 91 | 92 | //获取Padding 93 | // 获得它的父容器为它设置的测量模式和大小 94 | int sizeWidth = View.MeasureSpec.getSize(widthMeasureSpec); 95 | int sizeHeight = View.MeasureSpec.getSize(heightMeasureSpec); 96 | int modeWidth = View.MeasureSpec.getMode(widthMeasureSpec); 97 | int modeHeight = View.MeasureSpec.getMode(heightMeasureSpec); 98 | 99 | //FlowLayout最终的宽度和高度值 100 | int resultWidth = 0; 101 | int resultHeight = 0; 102 | 103 | //测量时每一行的宽度 104 | int lineWidth = 0; 105 | //测量时每一行的高度,加起来就是FlowLayout的高度 106 | int lineHeight = 0; 107 | 108 | //遍历每个子元素 109 | for (int i = 0, childCount = getChildCount(); i < childCount; i++) { 110 | View childView = getChildAt(i); 111 | //测量每一个子view的宽和高 112 | measureChild(childView, widthMeasureSpec, heightMeasureSpec); 113 | 114 | //获取到测量的宽和高 115 | int childWidth = childView.getMeasuredWidth(); 116 | int childHeight = childView.getMeasuredHeight(); 117 | 118 | //因为子View可能设置margin,这里要加上margin的距离 119 | ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) childView.getLayoutParams(); 120 | int realChildWidth = childWidth + mlp.leftMargin + mlp.rightMargin; 121 | int realChildHeight = childHeight + mlp.topMargin + mlp.bottomMargin; 122 | 123 | //如果当前一行的宽度加上要加入的子view的宽度大于父容器给的宽度,就换行 124 | if ((lineWidth + realChildWidth) > sizeWidth) { 125 | //换行 126 | resultWidth = Math.max(lineWidth, realChildWidth); 127 | resultHeight += realChildHeight; 128 | //换行了,lineWidth和lineHeight重新算 129 | lineWidth = realChildWidth; 130 | lineHeight = realChildHeight; 131 | } else { 132 | //不换行,直接相加 133 | lineWidth += realChildWidth; 134 | //每一行的高度取二者最大值 135 | lineHeight = Math.max(lineHeight, realChildHeight); 136 | } 137 | 138 | //遍历到最后一个的时候,肯定走的是不换行 139 | if (i == childCount - 1) { 140 | resultWidth = Math.max(lineWidth, resultWidth); 141 | resultHeight += lineHeight; 142 | } 143 | 144 | setMeasuredDimension(modeWidth == View.MeasureSpec.EXACTLY ? sizeWidth : resultWidth, 145 | modeHeight == View.MeasureSpec.EXACTLY ? sizeHeight : resultHeight); 146 | 147 | } 148 | 149 | } 150 | 151 | @Override 152 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 153 | 154 | int flowWidth = getWidth(); 155 | 156 | int childLeft = 0; 157 | int childTop = 0; 158 | 159 | //遍历子控件,记录每个子view的位置 160 | for (int i = 0, childCount = getChildCount(); i < childCount; i++) { 161 | View childView = getChildAt(i); 162 | 163 | //跳过View.GONE的子View 164 | if (childView.getVisibility() == View.GONE) { 165 | continue; 166 | } 167 | 168 | //获取到测量的宽和高 169 | int childWidth = childView.getMeasuredWidth(); 170 | int childHeight = childView.getMeasuredHeight(); 171 | 172 | //因为子View可能设置margin,这里要加上margin的距离 173 | ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) childView.getLayoutParams(); 174 | 175 | if (childLeft + mlp.leftMargin + childWidth + mlp.rightMargin > flowWidth) { 176 | //换行处理 177 | childTop += (mlp.topMargin + childHeight + mlp.bottomMargin); 178 | childLeft = 0; 179 | } 180 | //布局 181 | int left = childLeft + mlp.leftMargin; 182 | int top = childTop + mlp.topMargin; 183 | int right = childLeft + mlp.leftMargin + childWidth; 184 | int bottom = childTop + mlp.topMargin + childHeight; 185 | childView.layout(left, top, right, bottom); 186 | 187 | childLeft += (mlp.leftMargin + childWidth + mlp.rightMargin); 188 | } 189 | } 190 | 191 | @Override 192 | public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) { 193 | return new ViewGroup.MarginLayoutParams(getContext(), attrs); 194 | } 195 | 196 | public ListAdapter getAdapter() { 197 | return mAdapter; 198 | } 199 | 200 | class AdapterDataSetObserver extends DataSetObserver { 201 | @Override 202 | public void onChanged() { 203 | super.onChanged(); 204 | reloadData(); 205 | } 206 | 207 | @Override 208 | public void onInvalidated() { 209 | super.onInvalidated(); 210 | } 211 | } 212 | 213 | 214 | /** 215 | * 子View个数 216 | * 217 | * @param width 218 | */ 219 | public void setChildWidth(int width) { 220 | this.mWidth = width; 221 | } 222 | 223 | /** 224 | * 重新加载刷新数据 225 | */ 226 | private void reloadData() { 227 | removeAllViews(); 228 | 229 | ViewGroup.MarginLayoutParams mMarginLayoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 230 | if (mWidth != 0) { 231 | mMarginLayoutParams.width = mWidth; 232 | } 233 | boolean isSetted = false; 234 | for (int i = 0; i < mAdapter.getCount(); i++) { 235 | final int j = i; 236 | mCheckedTagArray.put(i, false); 237 | final View childView = mAdapter.getView(i, null, this); 238 | addView(childView, mMarginLayoutParams); 239 | 240 | if (mAdapter instanceof OnInitSelectedPosition) { 241 | boolean isSelected = ((OnInitSelectedPosition) mAdapter).isSelectedPosition(i); 242 | //判断一下模式 243 | if (mTagCheckMode == FLOW_TAG_CHECKED_SINGLE) { 244 | //单选只有第一个起作用 245 | if (isSelected && !isSetted) { 246 | mCheckedTagArray.put(i, true); 247 | childView.setSelected(true); 248 | isSetted = true; 249 | } 250 | } else if (mTagCheckMode == FLOW_TAG_CHECKED_MULTI) { 251 | if (isSelected) { 252 | mCheckedTagArray.put(i, true); 253 | childView.setSelected(true); 254 | } 255 | } 256 | } 257 | 258 | childView.setOnClickListener(new View.OnClickListener() { 259 | @Override 260 | public void onClick(View v) { 261 | if (mTagCheckMode == FLOW_TAG_CHECKED_NONE) { 262 | if (mOnTagClickListener != null) { 263 | mOnTagClickListener.onItemClick(FlowTagLayout.this, childView, j); 264 | } 265 | } else if (mTagCheckMode == FLOW_TAG_CHECKED_SINGLE) { 266 | //判断状态 267 | if (mCheckedTagArray.get(j)) { 268 | //单选模式下,必须选择一个 269 | // mCheckedTagArray.put(j, false); 270 | // childView.setSelected(false); 271 | // if (mOnTagSelectListener != null) { 272 | // mOnTagSelectListener.onItemSelect(FlowTagLayout.this, j,new ArrayList()); 273 | // } 274 | return; 275 | } 276 | //更新全部状态为fasle 277 | 278 | for (int k = 0; k < mAdapter.getCount(); k++) { 279 | mCheckedTagArray.put(k, false); 280 | getChildAt(k).setSelected(false); 281 | } 282 | //更新点击状态 283 | mCheckedTagArray.put(j, true); 284 | childView.setSelected(true); 285 | 286 | if (mOnTagSelectListener != null) { 287 | mOnTagSelectListener.onItemSelect(FlowTagLayout.this, j, Arrays.asList(j)); 288 | } 289 | } else if (mTagCheckMode == FLOW_TAG_CHECKED_MULTI) { 290 | if (mCheckedTagArray.get(j)) { 291 | mCheckedTagArray.put(j, false); 292 | childView.setSelected(false); 293 | } else { 294 | mCheckedTagArray.put(j, true); 295 | childView.setSelected(true); 296 | } 297 | //回调 298 | if (mOnTagSelectListener != null) { 299 | List list = new ArrayList(); 300 | for (int k = 0; k < mAdapter.getCount(); k++) { 301 | if (mCheckedTagArray.get(k)) { 302 | list.add(k); 303 | } 304 | } 305 | mOnTagSelectListener.onItemSelect(FlowTagLayout.this, j, list); 306 | } 307 | } 308 | } 309 | }); 310 | } 311 | } 312 | 313 | public void setOnTagClickListener(OnTagClickListener onTagClickListener) { 314 | this.mOnTagClickListener = onTagClickListener; 315 | } 316 | 317 | public void setOnTagSelectListener(OnTagSelectListener onTagSelectListener) { 318 | this.mOnTagSelectListener = onTagSelectListener; 319 | } 320 | 321 | /** 322 | * 像ListView、GridView一样使用FlowLayout 323 | * 324 | * @param adapter 325 | */ 326 | public void setAdapter(ListAdapter adapter) { 327 | if (mAdapter != null && mDataSetObserver != null) { 328 | mAdapter.unregisterDataSetObserver(mDataSetObserver); 329 | } 330 | 331 | //清除现有的数据 332 | removeAllViews(); 333 | mAdapter = adapter; 334 | 335 | if (mAdapter != null) { 336 | mDataSetObserver = new AdapterDataSetObserver(); 337 | mAdapter.registerDataSetObserver(mDataSetObserver); 338 | } 339 | } 340 | 341 | /** 342 | * 获取标签模式 343 | * 344 | * @return 345 | */ 346 | public int getmTagCheckMode() { 347 | return mTagCheckMode; 348 | } 349 | 350 | /** 351 | * 设置标签选中模式 352 | * 353 | * @param tagMode 354 | */ 355 | public void setTagCheckedMode(int tagMode) { 356 | this.mTagCheckMode = tagMode; 357 | } 358 | } 359 | -------------------------------------------------------------------------------- /app/src/main/java/com/cornflower1991/flowlayout/widget/OnInitSelectedPosition.java: -------------------------------------------------------------------------------- 1 | package com.cornflower1991.flowlayout.widget; 2 | 3 | /** 4 | * 初始化选择 5 | * Created by yexiuliang on 2016/7/11. 6 | */ 7 | 8 | public interface OnInitSelectedPosition { 9 | boolean isSelectedPosition(int position); 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/cornflower1991/flowlayout/widget/OnTagClickListener.java: -------------------------------------------------------------------------------- 1 | package com.cornflower1991.flowlayout.widget; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * 点击 7 | * Created by yexiuliang on 2016/7/11. 8 | */ 9 | public interface OnTagClickListener { 10 | void onItemClick(FlowTagLayout parent, View view, int position); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/cornflower1991/flowlayout/widget/OnTagSelectListener.java: -------------------------------------------------------------------------------- 1 | package com.cornflower1991.flowlayout.widget; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | *单选 多选 7 | * Created by yexiuliang on 2016/7/11. 8 | */ 9 | public interface OnTagSelectListener { 10 | void onItemSelect(FlowTagLayout parent, int positoin, List selectedList); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/blue_rect_round_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 18 | 19 | 27 | 28 | 29 | 32 | 33 | 40 | 41 | 46 | 47 | 52 | 53 | 59 | 60 | 64 | 65 | 66 | 71 | 72 | 73 | 78 | 79 | 83 | 84 | 85 | 90 | 91 | 96 | 97 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /app/src/main/res/layout/tag_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #ffffff 7 | 8 | #00000000 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FlowLayout 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 22 | 23 | 24 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/test/java/com/cornflower1991/flowlayout/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.cornflower1991.flowlayout; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /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.2.0-alpha5' 9 | 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 | -------------------------------------------------------------------------------- /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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 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-2.10-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 | -------------------------------------------------------------------------------- /images/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/images/1.png -------------------------------------------------------------------------------- /images/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/images/2.png -------------------------------------------------------------------------------- /images/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/images/3.png -------------------------------------------------------------------------------- /images/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/images/4.png -------------------------------------------------------------------------------- /images/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiushi123/FlowLayout-master/902ffdcd762c3bf13434b2a7d29dd51ea7d90955/images/5.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------