├── .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 |
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 |
--------------------------------------------------------------------------------
/.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 | # AutoFlowLayout
2 | ### 一、AutoFlowLayout应用场景
3 | 流式布局,在很多标签类的场景中可以用的;而网格布局在分类中以及自拍九宫格等场景很常见。如下所示:
4 | 
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 | 
29 |
30 | 
31 |
32 | **网格布局**
33 |
34 | 
35 |
36 | 最后一个是带间隔以及分割线的,由于录屏原因,只在跳过去的一瞬间显示了粉红色的一条线。真实如下图所示,可以定义横竖间距的大小,以及分割线的颜色,宽度。
37 | 
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 | 
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 |
16 |
24 |
32 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/grid_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/normal_flow.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
15 |
21 |
27 |
33 |
39 |
45 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/normal_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
12 |
18 |
24 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/special_flow.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
14 |
20 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/special_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/special_grid_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/special_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
22 |
23 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sub_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-xxhdpi/icon_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AutoFlow
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/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.2'
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/LRH1993/AutoFlowLayout/2a467480b2ac80d88f9428d8e2078c6f12c4c8d9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jul 27 11:39:24 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 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:26.+'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/library/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 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/example/library/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.library;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/library/src/main/java/com/example/library/AutoFlowLayout.java:
--------------------------------------------------------------------------------
1 | package com.example.library;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.drawable.Drawable;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.LinearLayout;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | /**
16 | *自定义LinearLayout,支持自动换行,指定行数,实现流式布局
17 | */
18 | public class AutoFlowLayout extends ViewGroup {
19 | /**
20 | * 存储所有的View,按行记录
21 | */
22 | private List> mAllViews = new ArrayList>();
23 | /**
24 | * 记录每一行的宽度
25 | */
26 | private List mWidthList = new ArrayList<>();
27 | /**
28 | * 记录设置单行显示的标志
29 | */
30 | private boolean mIsSingleLine;
31 | /**
32 | * 记录每一行的最大高度
33 | */
34 | private List mLineHeight = new ArrayList();
35 | /**
36 | * 记录设置最大行数量
37 | */
38 | private int mMaxLineNumbers;
39 | /**
40 | * 记录当前行数
41 | */
42 | private int mCount;
43 |
44 | /**
45 | * 是否还有数据没显示
46 | */
47 | private boolean mHasMoreData;
48 | /**
49 | * 子View的点击事件
50 | */
51 | private OnItemClickListener mOnItemClickListener;
52 | /**
53 | * 当前view的索引
54 | */
55 | private int mCurrentItemIndex=-1;
56 | /**
57 | * 多选标志,默认支持单选
58 | */
59 | private boolean mIsMultiChecked;
60 | /**
61 | * 记录选中的View
62 | */
63 | private View mSelectedView;
64 | /**
65 | *记录选中的View
66 | */
67 | private List mCheckedViews = new ArrayList<>();
68 | /**
69 | * 记录展示的数量
70 | */
71 | private int mDisplayNumbers;
72 | /**
73 | * 数据适配器
74 | */
75 | private FlowAdapter mAdapter;
76 | /**
77 | * 水平方向View之间的间距
78 | */
79 | private float mHorizontalSpace;
80 | /**
81 | * 竖直方向View之间的间距
82 | */
83 | private float mVerticalSpace;
84 | /**
85 | * 列数
86 | */
87 | private int mColumnNumbers;
88 | /**
89 | * 行数
90 | */
91 | private int mRowNumbers;
92 | /**
93 | * 是否设置了网格布局
94 | */
95 | private boolean mIsGridMode;
96 | /**
97 | * 是否设置了分割线
98 | */
99 | private boolean mIsCutLine;
100 | /**
101 | *记录分割线的宽度
102 | */
103 | private float mCutLineWidth;
104 | /**
105 | *记录分割线的长度
106 | */
107 | private int mCutLineColor;
108 | /**
109 | * 是否每行居中处理
110 | */
111 | private boolean mIsCenter;
112 | /**
113 | * 长按监听
114 | */
115 | private OnLongItemClickListener mOnLongItemClickListener;
116 | public AutoFlowLayout(Context context) {
117 | super(context);
118 | }
119 |
120 | public AutoFlowLayout(Context context, AttributeSet attrs) {
121 | super(context, attrs);
122 | init(context,attrs);
123 | }
124 |
125 | public AutoFlowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
126 | super(context, attrs, defStyleAttr);
127 | init(context,attrs);
128 | }
129 | private void init(Context context, AttributeSet attrs) {
130 | TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.AutoFlowLayout);
131 | mIsSingleLine = ta.getBoolean(R.styleable.AutoFlowLayout_singleLine,false);
132 | mMaxLineNumbers = ta.getInteger(R.styleable.AutoFlowLayout_maxLines,Integer.MAX_VALUE);
133 | mIsMultiChecked = ta.getBoolean(R.styleable.AutoFlowLayout_multiChecked,false);
134 | mHorizontalSpace = ta.getDimension(R.styleable.AutoFlowLayout_horizontalSpace,0);
135 | mVerticalSpace = ta.getDimension(R.styleable.AutoFlowLayout_verticalSpace,0);
136 | mColumnNumbers = ta.getInteger(R.styleable.AutoFlowLayout_columnNumbers,0);
137 | mRowNumbers = ta.getInteger(R.styleable.AutoFlowLayout_rowNumbers,0);
138 | mCutLineColor = ta.getColor(R.styleable.AutoFlowLayout_cutLineColor,getResources().getColor(android.R.color.darker_gray));
139 | mCutLineWidth = ta.getDimension(R.styleable.AutoFlowLayout_cutLineWidth,1f);
140 | mIsCutLine = ta.getBoolean(R.styleable.AutoFlowLayout_cutLine,false);
141 | mIsCenter = ta.getBoolean(R.styleable.AutoFlowLayout_lineCenter,false);
142 | if (mColumnNumbers != 0) {
143 | mIsGridMode = true;
144 | }
145 | ta.recycle();
146 | }
147 | @Override
148 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
149 | if (mIsGridMode) {
150 | setGridMeasure(widthMeasureSpec,heightMeasureSpec);
151 | } else {
152 | setFlowMeasure(widthMeasureSpec,heightMeasureSpec);
153 | }
154 |
155 |
156 | }
157 |
158 | /**
159 | * 网格布局的测量模式 默认各个子VIEW宽高值相同
160 | * @param widthMeasureSpec
161 | * @param heightMeasureSpec
162 | */
163 | private void setGridMeasure(int widthMeasureSpec, int heightMeasureSpec) {
164 | // 获得它的父容器为它设置的测量模式和大小
165 | int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
166 | int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
167 | int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
168 | int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
169 | //获取viewgroup的padding
170 | int paddingLeft = getPaddingLeft();
171 | int paddingRight = getPaddingRight();
172 | int paddingTop = getPaddingTop();
173 | int paddingBottom = getPaddingBottom();
174 | //最终的宽高值
175 | int heightResult;
176 | int widthResult;
177 | //未设置行数 推测行数
178 | if (mRowNumbers == 0) {
179 | mRowNumbers = getChildCount()%mColumnNumbers == 0 ?
180 | getChildCount()/mColumnNumbers : (getChildCount()/mColumnNumbers + 1);
181 | }
182 | int maxChildHeight = 0;
183 | int maxWidth = 0;
184 | int maxHeight = 0;
185 | int maxLineWidth = 0;
186 | //统计最大高度/最大宽度
187 | for (int i = 0; i < mRowNumbers; i++) {
188 | for (int j = 0; j < mColumnNumbers; j++) {
189 | final View child = getChildAt(i * mColumnNumbers + j);
190 | if (child != null) {
191 | if (child.getVisibility() != GONE) {
192 | measureChild(child,widthMeasureSpec,heightMeasureSpec);
193 | // 得到child的lp
194 | MarginLayoutParams lp = (MarginLayoutParams) child
195 | .getLayoutParams();
196 | maxLineWidth +=child.getMeasuredWidth()+lp.leftMargin+lp.rightMargin;
197 | maxChildHeight = Math.max(maxChildHeight, child.getMeasuredHeight()+lp.topMargin+lp.bottomMargin);
198 | }
199 | }
200 | }
201 | maxWidth = Math.max(maxLineWidth,maxWidth);
202 | maxLineWidth = 0;
203 | maxHeight += maxChildHeight;
204 | maxChildHeight = 0;
205 | }
206 | int tempWidth = (int) (maxWidth+mHorizontalSpace*(mColumnNumbers-1)+paddingLeft+paddingRight);
207 | int tempHeight = (int) (maxHeight+mVerticalSpace*(mRowNumbers-1)+paddingBottom+paddingTop);
208 | if (tempWidth > sizeWidth) {
209 | widthResult = sizeWidth;
210 | } else {
211 | widthResult = tempWidth;
212 | }
213 | //宽高超过屏幕大小,则进行压缩存放
214 | if (tempHeight > sizeHeight) {
215 | heightResult = sizeHeight;
216 | } else {
217 | heightResult = tempHeight;
218 | }
219 | setMeasuredDimension((modeWidth == MeasureSpec.EXACTLY) ? sizeWidth
220 | : widthResult, (modeHeight == MeasureSpec.EXACTLY) ? sizeHeight
221 | : heightResult);
222 | }
223 | /**
224 | * 流式布局的测量模式
225 | * @param widthMeasureSpec
226 | * @param heightMeasureSpec
227 | */
228 | private void setFlowMeasure(int widthMeasureSpec, int heightMeasureSpec) {
229 | mCount =0 ;
230 | // 获得它的父容器为它设置的测量模式和大小
231 | int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
232 | int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
233 | int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
234 | int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
235 | // 如果是warp_content情况下,记录宽和高
236 | int width = 0;
237 | int height = getPaddingTop() + getPaddingBottom();
238 | /**
239 | * 记录每一行的宽度,width不断取最大宽度
240 | */
241 | int lineWidth = getPaddingLeft() + getPaddingRight();
242 | /**
243 | * 每一行的高度,累加至height
244 | */
245 | int lineHeight = 0;
246 |
247 | int cCount = getChildCount();
248 |
249 | // 遍历每个子元素
250 | for (int i = 0; i < cCount; i++) {
251 | View child = getChildAt(i);
252 | // 测量每一个child的宽和高
253 | measureChild(child, widthMeasureSpec, heightMeasureSpec);
254 | // 得到child的lp
255 | MarginLayoutParams lp = (MarginLayoutParams) child
256 | .getLayoutParams();
257 | // 当前子空间实际占据的宽度
258 | int childWidth = child.getMeasuredWidth() + lp.leftMargin
259 | + lp.rightMargin;
260 | // 当前子空间实际占据的高度
261 | int childHeight = child.getMeasuredHeight() + lp.topMargin
262 | + lp.bottomMargin;
263 | /**
264 | * 如果加入当前child,则超出最大宽度,则的到目前最大宽度给width,类加height 然后开启新行
265 | */
266 | if (lineWidth + childWidth > sizeWidth) {
267 | width = Math.max(lineWidth, childWidth);// 取最大的
268 | lineWidth = childWidth; // 重新开启新行,开始记录
269 | // 叠加当前高度,
270 | height += lineHeight;
271 | // 开启记录下一行的高度
272 | lineHeight = childHeight;
273 | mCount++;
274 | if (mCount>=mMaxLineNumbers) {
275 | setHasMoreData(i+1,cCount);
276 | break;
277 | }
278 | if (mIsSingleLine) {
279 | setHasMoreData(i+1,cCount);
280 | break;
281 | }
282 | } else
283 | // 否则累加值lineWidth,lineHeight取最大高度
284 | {
285 | lineWidth += childWidth;
286 | lineHeight = Math.max(lineHeight, childHeight);
287 | }
288 | // 如果是最后一个,则将当前记录的最大宽度和当前lineWidth做比较
289 | if (i == cCount - 1) {
290 | width = Math.max(width, lineWidth);
291 | height += lineHeight;
292 | }
293 |
294 | }
295 | setMeasuredDimension((modeWidth == MeasureSpec.EXACTLY) ? sizeWidth
296 | : width, (modeHeight == MeasureSpec.EXACTLY) ? sizeHeight
297 | : height);
298 | }
299 |
300 | @Override
301 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
302 | if (mIsGridMode) {
303 | setGridLayout();
304 | } else {
305 | setFlowLayout();
306 | }
307 | }
308 | /**
309 | * 网格布局的布局模式
310 | */
311 | private void setGridLayout() {
312 | mCheckedViews.clear();
313 | mCurrentItemIndex = -1;
314 | int sizeWidth = getWidth();
315 | int sizeHeight = getHeight();
316 | //子View的平均宽高 默认所有View宽高一致
317 | View tempChild = getChildAt(0);
318 | MarginLayoutParams lp = (MarginLayoutParams) tempChild
319 | .getLayoutParams();
320 | int childAvWidth = (int) ((sizeWidth - getPaddingLeft() - getPaddingRight() - mHorizontalSpace * (mColumnNumbers-1))/mColumnNumbers)-lp.leftMargin-lp.rightMargin;
321 | int childAvHeight = (int) ((sizeHeight - getPaddingTop() - getPaddingBottom() - mVerticalSpace * (mRowNumbers-1))/mRowNumbers)-lp.topMargin-lp.bottomMargin;
322 | for (int i = 0; i < mRowNumbers; i++) {
323 | for (int j = 0; j < mColumnNumbers; j++) {
324 | final View child = getChildAt(i * mColumnNumbers + j);
325 | if (child != null) {
326 | mCurrentItemIndex++;
327 | if (child.getVisibility() != View.GONE) {
328 | setChildClickOperation(child, -1);
329 | int childLeft = (int) (getPaddingLeft() + j * (childAvWidth + mHorizontalSpace))+j * (lp.leftMargin + lp.rightMargin) + lp.leftMargin;
330 | int childTop = (int) (getPaddingTop() + i * (childAvHeight + mVerticalSpace)) + i * (lp.topMargin + lp.bottomMargin) + lp.topMargin;
331 | child.layout(childLeft, childTop, childLeft + childAvWidth, childAvHeight +childTop);
332 | }
333 | }
334 | }
335 | }
336 | }
337 |
338 | /**
339 | * 流式布局的布局模式
340 | */
341 | private void setFlowLayout() {
342 | mCurrentItemIndex = -1;
343 | mCount = 0;
344 | mAllViews.clear();
345 | mLineHeight.clear();
346 | mWidthList.clear();
347 | mCheckedViews.clear();
348 | int width = getWidth();
349 |
350 | int lineWidth = getPaddingLeft();
351 | int lineHeight = getPaddingTop();
352 | // 存储每一行所有的childView
353 | List lineViews = new ArrayList();
354 | int cCount = getChildCount();
355 | // 遍历所有的孩子
356 | for (int i = 0; i < cCount; i++) {
357 | View child = getChildAt(i);
358 | MarginLayoutParams lp = (MarginLayoutParams) child
359 | .getLayoutParams();
360 | int childWidth = child.getMeasuredWidth();
361 | int childHeight = child.getMeasuredHeight();
362 |
363 | // 如果已经需要换行
364 | if (childWidth + lp.leftMargin + lp.rightMargin + getPaddingRight() + lineWidth > width) {
365 | // 记录这一行所有的View以及最大高度
366 | mLineHeight.add(lineHeight);
367 | // 将当前行的childView保存,然后开启新的ArrayList保存下一行的childView
368 | mAllViews.add(lineViews);
369 | mWidthList.add(lp.leftMargin + lp.rightMargin + getPaddingRight() + lineWidth);
370 | lineWidth = 0;// 重置行宽
371 | lineViews = new ArrayList();
372 | mCount++;
373 | if (mCount>=mMaxLineNumbers) {
374 | setHasMoreData(i+1,cCount);
375 | break;
376 | }
377 | if (mIsSingleLine) {
378 | setHasMoreData(i+1,cCount);
379 | break;
380 | }
381 | }
382 | /**
383 | * 如果不需要换行,则累加
384 | */
385 | lineWidth += childWidth + lp.leftMargin + lp.rightMargin;
386 | lineHeight = Math.max(lineHeight, childHeight + lp.topMargin
387 | + lp.bottomMargin);
388 | lineViews.add(child);
389 | }
390 | // 记录最后一行
391 | mLineHeight.add(lineHeight);
392 | mAllViews.add(lineViews);
393 | mWidthList.add(lineWidth);
394 | int left = getPaddingLeft();
395 | int top = getPaddingTop();
396 | // 得到总行数
397 | int lineNums = mAllViews.size();
398 | if (mAllViews.get(mAllViews.size()-1).size() == 0){
399 | lineNums = mAllViews.size()-1;
400 | }
401 | for (int i = 0; i < lineNums; i++) {
402 | // 每一行的所有的views
403 | lineViews = mAllViews.get(i);
404 | // 当前行的最大高度
405 | lineHeight = mLineHeight.get(i);
406 | if (mIsCenter) {
407 | if (mWidthList.get(i) views) {
570 | removeAllViews();
571 | if (views == null || views.size() == 0) {
572 | return;
573 | }
574 | for (int i = 0; i < views.size(); i++) {
575 | View view = views.get(i);
576 | addView(view);
577 | }
578 | requestLayout();
579 | }
580 | /**
581 | * 删除指定索引的view
582 | * @param index true删除成功 false删除失败
583 | * @return
584 | */
585 | public boolean deleteView(int index) {
586 | if (mCurrentItemIndex != 0) {
587 | mDisplayNumbers = mCurrentItemIndex;
588 | if (index > mDisplayNumbers) {
589 | return false;
590 | } else {
591 | removeViewAt(index);
592 | return true;
593 | }
594 | }
595 | return false;
596 | }
597 |
598 | /**
599 | * 删除最后一个view
600 | * @return true删除成功 false删除失败
601 | */
602 | public boolean deleteView() {
603 | if (mCurrentItemIndex != 0) {
604 | mDisplayNumbers = mCurrentItemIndex;
605 | removeViewAt(mDisplayNumbers);
606 | return true;
607 | }
608 | return false;
609 | }
610 |
611 | /**
612 | * 删除指定范围的所有view
613 | * @param start 开始范围
614 | * @param end 结束范围
615 | * @return
616 | */
617 | public boolean deleteView(int start, int end) {
618 | if (mCurrentItemIndex != 0) {
619 | mDisplayNumbers = mCurrentItemIndex;
620 | if (start < 0) {
621 | start = 0;
622 | }
623 | if (end > mDisplayNumbers) {
624 | end = mDisplayNumbers;
625 | }
626 | removeViews(start,end-start+1);
627 | return true;
628 | }
629 | return false;
630 | }
631 |
632 | /**
633 | * 删除所有view
634 | * @return
635 | */
636 | public boolean clearViews(){
637 | if (getChildCount() > 0) {
638 | removeAllViews();
639 | return true;
640 | }
641 | return false;
642 | }
643 |
644 |
645 | /**
646 | * 设置最多显示的行数
647 | * @param number
648 | */
649 | public void setMaxLines(int number) {
650 | mMaxLineNumbers = number;
651 | requestLayout();
652 | }
653 |
654 | /**
655 | * 是否只显示单行
656 | * @param isSingle
657 | */
658 | public void setSingleLine(boolean isSingle) {
659 | mIsSingleLine = isSingle;
660 | requestLayout();
661 | }
662 |
663 | /**
664 | * 是否单行显示
665 | * @return true 单行显示 false 多行显示
666 | */
667 | public boolean isSingleLine() {
668 | return mIsSingleLine;
669 | }
670 |
671 | /**
672 | * 支持显示的最大行数
673 | * @return 最大行数
674 | */
675 | public int getMaxLineNumbers() {
676 | return mMaxLineNumbers;
677 | }
678 |
679 | /**
680 | * 是否还有更多数据未显示
681 | * @return true 还有未显示数据 false 完全显示
682 | */
683 | public boolean hasMoreData() {
684 | return mHasMoreData;
685 | }
686 |
687 | /**
688 | * 是否支持多选
689 | * @return
690 | */
691 | public boolean isMultiChecked() {
692 | return mIsMultiChecked;
693 | }
694 | public void setMultiChecked(boolean isMultiChecked) {
695 | mIsMultiChecked = isMultiChecked;
696 | }
697 |
698 | /**
699 | * 获得选中的View集合
700 | * @return view集合
701 | */
702 | public List getCheckedViews() {
703 | if (mIsMultiChecked) {
704 | return mCheckedViews;
705 | } else {
706 | mCheckedViews.add(mSelectedView);
707 | return mCheckedViews;
708 | }
709 | }
710 |
711 | /**
712 | * 获取上一个被选中的View
713 | * @return 被选中的view
714 | */
715 | public View getSelectedView() {
716 | return mSelectedView;
717 | }
718 |
719 | /**
720 | * 设置数据适配器
721 | * @param adapter
722 | */
723 | public void setAdapter(FlowAdapter adapter) {
724 | mAdapter = adapter;
725 | if (mAdapter.getCount() != 0) {
726 | for (int i = 0; i < mAdapter.getCount(); i ++) {
727 | View view = mAdapter.getView(i);
728 | addView(view);
729 | }
730 | requestLayout();
731 | }
732 | }
733 |
734 | /**
735 | * 设置网格布局的水平间距
736 | * @param horizontalSpace 单位px
737 | */
738 | public void setHorizontalSpace(int horizontalSpace) {
739 | mHorizontalSpace = horizontalSpace;
740 | requestLayout();
741 | }
742 |
743 | /**
744 | * 返回网格布局的水平距离
745 | * @return
746 | */
747 | public float getHorizontalSpace() {
748 | return mHorizontalSpace;
749 | }
750 |
751 | /**
752 | * 设置网格布局的垂直间距
753 | * @param verticalSpace 单位px
754 | */
755 | public void setVerticalSpace(int verticalSpace) {
756 | mVerticalSpace = verticalSpace;
757 | requestLayout();
758 | }
759 | /**
760 | * 返回网格布局的垂直距离
761 | */
762 | public float getVerticalSpace() {
763 | return mVerticalSpace;
764 | }
765 |
766 | /**
767 | * 设置列数
768 | * @param columnNumbers
769 | */
770 | public void setColumnNumbers(int columnNumbers) {
771 | mColumnNumbers = columnNumbers;
772 | requestLayout();
773 | }
774 |
775 | /**
776 | * 获得列数
777 | * @return
778 | */
779 | public int getColumnNumbers() {
780 | return mColumnNumbers;
781 | }
782 |
783 | /**
784 | * 设置行数
785 | * @param rowNumbers
786 | */
787 | public void setRowNumbers(int rowNumbers) {
788 | mRowNumbers = rowNumbers;
789 | requestLayout();
790 | }
791 |
792 | /**
793 | * 得到行数
794 | * @return
795 | */
796 | public int getRowNumbers() {
797 | return mRowNumbers;
798 | }
799 |
800 | /**
801 | * 设置分割线的宽度
802 | * @param width
803 | */
804 | public void setCutLineWidth (float width) {
805 | mCutLineWidth = width;
806 | invalidate();
807 | }
808 |
809 | /**
810 | * 获取分割线的宽度
811 | * @return
812 | */
813 | public float getCutLineWidth() {
814 | return mCutLineWidth;
815 | }
816 |
817 | /**
818 | * 设置分割线的颜色
819 | * @param color
820 | */
821 | public void setCutLineColor (int color) {
822 | mCutLineColor = color;
823 | invalidate();
824 | }
825 |
826 | /**
827 | * 获取分割线的颜色
828 | * @return
829 | */
830 | public int getCutLineColor () {
831 | return mCutLineColor;
832 | }
833 |
834 | /**
835 | * 设置分割线
836 | * @param isCutLine true 设置 false 不设置
837 | */
838 | public void setCutLine(boolean isCutLine) {
839 | mIsCutLine = isCutLine;
840 | invalidate();
841 | }
842 |
843 | /**
844 | * 是否设置了分割线
845 | * @return
846 | */
847 | public boolean hasCutLine() {
848 | return mIsCutLine;
849 | }
850 |
851 | /**
852 | * 设置是否进行行居中显示
853 | * @param isCenter
854 | */
855 | public void setLineCenter(boolean isCenter) {
856 | mIsCenter = isCenter;
857 | requestLayout();
858 | }
859 |
860 | /**
861 | * 是否设置了行居中显示
862 | * @return
863 | */
864 | public boolean isLineCenter() {
865 | return mIsCenter;
866 | }
867 |
868 | public interface OnItemClickListener{
869 | void onItemClick(int position,View view);
870 | }
871 | public void setOnItemClickListener(OnItemClickListener onItemClickListener){
872 | mOnItemClickListener = onItemClickListener;
873 | }
874 | public interface OnLongItemClickListener{
875 | void onLongItemClick(int position,View view);
876 | }
877 | public void setOnLongItemClickListener(OnLongItemClickListener onLongItemClickListener){
878 | mOnLongItemClickListener = onLongItemClickListener;
879 | }
880 |
881 |
882 | }
883 |
--------------------------------------------------------------------------------
/library/src/main/java/com/example/library/FlowAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.library;
2 |
3 | import android.view.View;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | /**
10 | * Created by lvruheng on 2017/8/1.
11 | */
12 |
13 | public abstract class FlowAdapter {
14 | private List mList;
15 |
16 | public FlowAdapter(List datas) {
17 | mList = datas;
18 | }
19 | public FlowAdapter(T[] datas) {
20 | mList = new ArrayList(Arrays.asList(datas));
21 | }
22 |
23 | public T getItem(int position) {
24 | return mList.get(position);
25 | }
26 |
27 | public int getCount() {
28 | return mList == null ? 0 : mList.size();
29 | }
30 |
31 | public abstract View getView(int position);
32 | }
33 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/library/src/test/java/com/example/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.library;
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 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------