├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── gen │ └── com │ │ └── example │ │ └── lvruheng │ │ └── superlinelayout │ │ ├── BuildConfig.java │ │ ├── Manifest.java │ │ └── R.java │ ├── java │ └── com │ │ └── example │ │ └── lvruheng │ │ └── autoflowlayout │ │ ├── MainActivity.java │ │ ├── NormalFlowActivity.java │ │ ├── NormalGridActivity.java │ │ ├── SpecialFlowActivity.java │ │ └── SpecialGridActivity.java │ └── res │ ├── color │ └── btn_common_text.xml │ ├── drawable │ ├── bg_sub_tag.xml │ ├── delete.png │ └── grid_icon.jpg │ ├── layout │ ├── activity_main.xml │ ├── grid_item.xml │ ├── normal_flow.xml │ ├── normal_grid.xml │ ├── special_flow.xml │ ├── special_grid.xml │ ├── special_grid_item.xml │ ├── special_item.xml │ └── sub_item.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_round.png │ └── icon_launcher.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── library │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── library │ │ │ ├── AutoFlowLayout.java │ │ │ └── FlowAdapter.java │ └── res │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── example │ └── library │ └── ExampleUnitTest.java └── 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 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.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/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.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 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoFlowLayout 2 | ### 一、AutoFlowLayout应用场景 3 | 流式布局,在很多标签类的场景中可以用的;而网格布局在分类中以及自拍九宫格等场景很常见。如下所示: 4 | ![](http://upload-images.jianshu.io/upload_images/3985563-8c7c5401f2602718.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 5 | 如此使用频繁而又实现简单的控件,怎能不自己撸一个呢?控件,还是定制的好啊。 6 | ### 二、AutoFlowLayout实现效果 7 | 先介绍下自己撸的这个控件的功能及效果。 8 | #### 1.功能 9 | **流式布局** 10 | - 自动换行 11 | - 行数自定:单行/多行 12 | - 支持单选/多选 13 | - 支持行居中/靠左显示 14 | - 支持添加/删除子View 15 | - 支持子View点击/长按事件 16 | 17 | **网格布局** 18 | - 行数/列数自定 19 | - 支持单选/多选 20 | - 支持添加/删除子View 21 | - 支持子View点击/长按事件 22 | - 支持添加多样式分割线及横竖间隔 23 | #### 2.效果 24 | 下面以gif图的形式展现下实现的效果,样式简单了些,不过依然能展示出这个简单控件的多功能实用性。 25 | 26 | **流式布局** 27 | 28 | ![](http://upload-images.jianshu.io/upload_images/3985563-a0d0d19ddb77a9df.gif?imageMogr2/auto-orient/strip) 29 | 30 | ![](http://upload-images.jianshu.io/upload_images/3985563-e3ae7ae58423c373.gif?imageMogr2/auto-orient/strip) 31 | 32 | **网格布局** 33 | 34 | ![](http://upload-images.jianshu.io/upload_images/3985563-3723ba8a6b0c1114.gif?imageMogr2/auto-orient/strip) 35 | 36 | 最后一个是带间隔以及分割线的,由于录屏原因,只在跳过去的一瞬间显示了粉红色的一条线。真实如下图所示,可以定义横竖间距的大小,以及分割线的颜色,宽度。 37 | ![](http://upload-images.jianshu.io/upload_images/3985563-ba1e847f4c039f3c.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 38 | ### 三、AutoFlowLayout使用 39 | #### 1.添加依赖 40 | ①.在项目的 build.gradle 文件中添加 41 | ``` 42 | allprojects { 43 | repositories { 44 | ... 45 | maven { url 'https://jitpack.io' } 46 | } 47 | } 48 | ``` 49 | ②.在 module 的 build.gradle 文件中添加依赖 50 | ``` 51 | dependencies { 52 | compile 'com.github.LRH1993:AutoFlowLayout:1.0.5' 53 | } 54 | ``` 55 | #### 2.属性说明 56 | 下表是自定义的属性说明,可在xml中声明,同时有对应的get/set方法,可在代码中动态添加。 57 | ![](http://upload-images.jianshu.io/upload_images/3985563-9cc258fb8363af39.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 58 | #### 3.使用示例 59 | **布局** 60 | ``` 61 | 62 | 65 | 69 | 70 | ``` 71 | **代码设置数据** 72 | ``` 73 | mFlowLayout.setAdapter(new FlowAdapter(Arrays.asList(mData)) { 74 | @Override 75 | public View getView(int position) { 76 | View item = mLayoutInflater.inflate(R.layout.special_item, null); 77 | TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag); 78 | tvAttrTag.setText(mData[position]); 79 | return item; 80 | } 81 | }); 82 | ``` 83 | 与ListView,GridView使用方式一样,实现FlowAdapter即可。 84 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.0" 6 | defaultConfig { 7 | applicationId "com.example.lvruheng.autoflowlayout" 8 | minSdkVersion 21 9 | targetSdkVersion 26 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(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:26.+' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testCompile 'junit:junit:4.12' 30 | compile project(':library') 31 | } 32 | -------------------------------------------------------------------------------- /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 /Users/lvruheng/Library/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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/gen/com/example/lvruheng/superlinelayout/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package com.example.lvruheng.autoflowlayout; 4 | 5 | /* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */ 6 | public final class BuildConfig { 7 | public final static boolean DEBUG = Boolean.parseBoolean(null); 8 | } -------------------------------------------------------------------------------- /app/src/main/gen/com/example/lvruheng/superlinelayout/Manifest.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package com.example.lvruheng.autoflowlayout; 4 | 5 | /* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */ 6 | public final class Manifest { 7 | } -------------------------------------------------------------------------------- /app/src/main/gen/com/example/lvruheng/superlinelayout/R.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package com.example.lvruheng.autoflowlayout; 4 | 5 | /* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */ 6 | public final class R { 7 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/lvruheng/autoflowlayout/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.lvruheng.autoflowlayout; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.TextView; 10 | import android.widget.Toast; 11 | 12 | 13 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | Button normalFlow = (Button) findViewById(R.id.tv_normal_flow); 20 | Button specialFlow = (Button) findViewById(R.id.tv_special_flow); 21 | Button normalGrid = (Button) findViewById(R.id.tv_normal_grid); 22 | Button specialGrid = (Button) findViewById(R.id.tv_special_grid); 23 | normalFlow.setOnClickListener(this); 24 | specialFlow.setOnClickListener(this); 25 | normalGrid.setOnClickListener(this); 26 | specialGrid.setOnClickListener(this); 27 | } 28 | 29 | @Override 30 | public void onClick(View view) { 31 | switch (view.getId()) { 32 | case R.id.tv_normal_flow :{ 33 | Intent intent = new Intent(MainActivity.this,NormalFlowActivity.class); 34 | startActivity(intent); 35 | break; 36 | } 37 | case R.id.tv_special_flow :{ 38 | Intent intent = new Intent(MainActivity.this,SpecialFlowActivity.class); 39 | startActivity(intent); 40 | break; 41 | } 42 | case R.id.tv_normal_grid :{ 43 | Intent intent = new Intent(MainActivity.this,NormalGridActivity.class); 44 | startActivity(intent); 45 | break; 46 | } 47 | case R.id.tv_special_grid :{ 48 | Intent intent = new Intent(MainActivity.this,SpecialGridActivity.class); 49 | startActivity(intent); 50 | break; 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/lvruheng/autoflowlayout/NormalFlowActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.lvruheng.autoflowlayout; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.TextView; 10 | 11 | import com.example.library.AutoFlowLayout; 12 | 13 | /** 14 | * Created by lvruheng on 2017/8/4. 15 | */ 16 | 17 | public class NormalFlowActivity extends AppCompatActivity implements View.OnClickListener { 18 | private AutoFlowLayout mFlowLayout; 19 | private String[] mData = {"Java","C++","Python","JavaScript","Ruby","Swift","MATLAB","Scratch","Drat","ABAP","COBOL","Fortran","Scala","Lisp", 20 | "Kotlin","Erlang","Groovy","Scheme","Rust","Logo","Prolog","LabVIEW"}; 21 | private LayoutInflater mLayoutInflater; 22 | private Button mSingleButton; 23 | private Button mMultiLineButton; 24 | private Button mAddButton; 25 | private Button mDeleteButton; 26 | private Button mMultiSelectedButton; 27 | private Button mCenterButton; 28 | private int count = 10; 29 | @Override 30 | protected void onCreate(@Nullable Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.normal_flow); 33 | mFlowLayout = (AutoFlowLayout) findViewById(R.id.afl_cotent); 34 | mLayoutInflater = LayoutInflater.from(this); 35 | mSingleButton = (Button) findViewById(R.id.bt_single); 36 | mMultiLineButton = (Button) findViewById(R.id.bt_multi); 37 | mAddButton = (Button) findViewById(R.id.bt_add); 38 | mDeleteButton = (Button) findViewById(R.id.bt_delete); 39 | mMultiSelectedButton = (Button) findViewById(R.id.bt_checked); 40 | mCenterButton = (Button) findViewById(R.id.bt_center); 41 | mSingleButton.setOnClickListener(this); 42 | mMultiLineButton.setOnClickListener(this); 43 | mAddButton.setOnClickListener(this); 44 | mDeleteButton.setOnClickListener(this); 45 | mMultiSelectedButton.setOnClickListener(this); 46 | mCenterButton.setOnClickListener(this); 47 | for (int i = 0; i< 10; i ++ ){ 48 | View item = mLayoutInflater.inflate(R.layout.sub_item, null); 49 | TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag); 50 | tvAttrTag.setText(mData[i]); 51 | mFlowLayout.addView(item); 52 | } 53 | } 54 | 55 | @Override 56 | public void onClick(View view) { 57 | switch (view.getId()) { 58 | case R.id.bt_single:{ 59 | mFlowLayout.setLineCenter(false); 60 | mFlowLayout.setSingleLine(true); 61 | mFlowLayout.setMaxLines(1); 62 | break; 63 | } 64 | case R.id.bt_multi:{ 65 | mFlowLayout.setLineCenter(false); 66 | mFlowLayout.setSingleLine(false); 67 | mFlowLayout.setMaxLines(2); 68 | break; 69 | } 70 | case R.id.bt_add:{ 71 | mFlowLayout.setLineCenter(false); 72 | if (count>=mData.length){ 73 | return; 74 | } 75 | View item = mLayoutInflater.inflate(R.layout.sub_item, null); 76 | TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag); 77 | tvAttrTag.setText(mData[count]); 78 | mFlowLayout.setSingleLine(false); 79 | mFlowLayout.setMaxLines(Integer.MAX_VALUE); 80 | mFlowLayout.addView(item); 81 | count++; 82 | break; 83 | } 84 | case R.id.bt_delete:{ 85 | mFlowLayout.setLineCenter(false); 86 | mFlowLayout.deleteView(); 87 | break; 88 | } 89 | 90 | case R.id.bt_checked:{ 91 | mFlowLayout.setLineCenter(false); 92 | mFlowLayout.setMultiChecked(true); 93 | break; 94 | } 95 | case R.id.bt_center:{ 96 | mFlowLayout.setLineCenter(true); 97 | break; 98 | } 99 | 100 | 101 | 102 | 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/lvruheng/autoflowlayout/NormalGridActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.lvruheng.autoflowlayout; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.widget.Button; 9 | 10 | import com.example.library.AutoFlowLayout; 11 | import com.example.library.FlowAdapter; 12 | 13 | import java.util.Arrays; 14 | 15 | /** 16 | * Created by lvruheng on 2017/8/4. 17 | */ 18 | 19 | public class NormalGridActivity extends AppCompatActivity implements View.OnClickListener{ 20 | private Button mAddButton; 21 | private Button mDeleteButton; 22 | private AutoFlowLayout mFlowLayout; 23 | private int count =6; 24 | private String[] mData = {"Java", "C++", "Python", "JavaScript", "Ruby", "Swift"}; 25 | private LayoutInflater mLayoutInflater; 26 | @Override 27 | protected void onCreate(@Nullable Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.normal_grid); 30 | mAddButton = (Button) findViewById(R.id.bt_add); 31 | mDeleteButton = (Button) findViewById(R.id.bt_delete); 32 | mAddButton.setOnClickListener(this); 33 | mDeleteButton.setOnClickListener(this); 34 | mLayoutInflater = LayoutInflater.from(this); 35 | mFlowLayout = (AutoFlowLayout) findViewById(R.id.afl_cotent); 36 | mFlowLayout.setAdapter(new FlowAdapter(Arrays.asList(mData)) { 37 | @Override 38 | public View getView(int position) { 39 | View item = mLayoutInflater.inflate(R.layout.grid_item, null); 40 | return item; 41 | } 42 | }); 43 | } 44 | 45 | @Override 46 | public void onClick(View view) { 47 | switch (view.getId()) { 48 | case R.id.bt_add:{ 49 | count++; 50 | mFlowLayout.setRowNumbers(count%3 == 0 ? count/3 : count/3 + 1); 51 | View item = mLayoutInflater.inflate(R.layout.grid_item, null); 52 | mFlowLayout.addView(item); 53 | break; 54 | } 55 | case R.id.bt_delete:{ 56 | count--; 57 | mFlowLayout.setRowNumbers(count%3 == 0 ? count/3 : count/3 + 1); 58 | mFlowLayout.deleteView(); 59 | break; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/lvruheng/autoflowlayout/SpecialFlowActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.lvruheng.autoflowlayout; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | import android.widget.Toast; 12 | 13 | import com.example.library.AutoFlowLayout; 14 | import com.example.library.FlowAdapter; 15 | 16 | import java.util.Arrays; 17 | 18 | /** 19 | * Created by lvruheng on 2017/8/4. 20 | */ 21 | 22 | public class SpecialFlowActivity extends AppCompatActivity { 23 | private Button mChangeButton; 24 | private Button mLongClickButton; 25 | private AutoFlowLayout mFlowLayout; 26 | private String[] mData = {"Java", "C++", "Python", "JavaScript", "Ruby", "Swift", "MATLAB", "Scratch", "Drat", "ABAP", "COBOL", "Fortran", "Scala", "Lisp", 27 | "Kotlin", "Erlang", "Groovy", "Scheme", "Rust", "Logo", "Prolog", "LabVIEW"}; 28 | private LayoutInflater mLayoutInflater; 29 | 30 | @Override 31 | protected void onCreate(@Nullable Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.special_flow); 34 | mChangeButton = (Button) findViewById(R.id.bt_change); 35 | mLayoutInflater = LayoutInflater.from(this); 36 | mLongClickButton = (Button) findViewById(R.id.bt_long_click); 37 | mFlowLayout = (AutoFlowLayout) findViewById(R.id.afl_cotent); 38 | mFlowLayout.setAdapter(new FlowAdapter(Arrays.asList(mData)) { 39 | @Override 40 | public View getView(int position) { 41 | View item = mLayoutInflater.inflate(R.layout.special_item, null); 42 | TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag); 43 | tvAttrTag.setText(mData[position]); 44 | return item; 45 | } 46 | }); 47 | mFlowLayout.setOnItemClickListener(new AutoFlowLayout.OnItemClickListener() { 48 | @Override 49 | public void onItemClick(int position, View view) { 50 | Toast.makeText(SpecialFlowActivity.this, mData[position], Toast.LENGTH_SHORT).show(); 51 | } 52 | }); 53 | mFlowLayout.setOnLongItemClickListener(new AutoFlowLayout.OnLongItemClickListener() { 54 | @Override 55 | public void onLongItemClick(int position, View view) { 56 | ImageView imageView = view.findViewById(R.id.iv_delete); 57 | imageView.setVisibility(View.VISIBLE); 58 | } 59 | }); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/lvruheng/autoflowlayout/SpecialGridActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.lvruheng.autoflowlayout; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | 9 | import com.example.library.AutoFlowLayout; 10 | import com.example.library.FlowAdapter; 11 | 12 | import java.util.Arrays; 13 | 14 | /** 15 | * Created by lvruheng on 2017/8/4. 16 | */ 17 | 18 | public class SpecialGridActivity extends AppCompatActivity { 19 | private AutoFlowLayout mFlowLayout; 20 | private LayoutInflater mLayoutInflater; 21 | private String[] mData = {"Java", "C++", "Python", "JavaScript", "Ruby", "Swift","Swift","MATLAB","Scratch"}; 22 | @Override 23 | protected void onCreate(@Nullable Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.special_grid); 26 | mLayoutInflater = LayoutInflater.from(this); 27 | mFlowLayout = (AutoFlowLayout) findViewById(R.id.afl_cotent); 28 | mFlowLayout.setAdapter(new FlowAdapter(Arrays.asList(mData)) { 29 | @Override 30 | public View getView(int position) { 31 | View item = mLayoutInflater.inflate(R.layout.special_grid_item, null); 32 | return item; 33 | } 34 | }); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/res/color/btn_common_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_sub_tag.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/drawable/delete.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/grid_icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/drawable/grid_icon.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 |