├── .gitignore
├── README.md
├── build.gradle
├── fluidlayout
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── fynn
│ │ └── fluidlayout
│ │ └── FluidLayout.java
│ └── res
│ └── values
│ ├── attrs.xml
│ └── strings.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── fynn
│ │ └── fluidlayout
│ │ └── sample
│ │ └── MainActivity.java
│ └── res
│ ├── drawable
│ ├── text_bg.xml
│ └── text_bg_highlight.xml
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── settings.gradle
└── snapshot
├── demo_gif.gif
└── snapshot.png
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Eclipse project files
30 | .classpath
31 | .project
32 | project.properties
33 |
34 | # IDEA project files
35 | *.iml
36 | .idea/
37 |
38 | # OS generated files
39 | .DS_Store
40 | .DS_Store?
41 | ._*
42 | .Spotlight-V100
43 | .Trashes
44 | ehthumbs.db
45 | Thumbs.db
46 |
47 | # others
48 | ant.properties
49 | build.xml
50 | map.txt
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FluidLayout简介
2 | FluidLayout是一个Android平台上的开源控件,提供了流布局的布局方式。
3 |
4 | `在 Gradle 项目中添加依赖:`
5 | ```
6 | compile 'com.fynn.fluidlayout:fluidlayout:1.0'
7 | ```
8 |
9 | `支持的布局属性:`
10 |
11 | > gravity="center" 单行垂直居中对齐
12 |
13 | > gravity="bottom" 单行底部对其
14 |
15 | > gravity="top" 单行顶部对其
16 |
17 | 该控件支持 `ScrollView` 嵌套。
18 |
19 | # Snapshot
20 | 
21 | 
22 |
23 | # License
24 |
25 | Copyright Fynn
26 |
27 | Licensed under the Apache License, Version 2.0 (the "License");
28 | you may not use this file except in compliance with the License.
29 | You may obtain a copy of the License at
30 |
31 | [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
32 |
33 | Unless required by applicable law or agreed to in writing, software
34 | distributed under the License is distributed on an "AS IS" BASIS,
35 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 | See the License for the specific language governing permissions and
37 | limitations under the License.
38 |
--------------------------------------------------------------------------------
/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.1.0'
9 |
10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/fluidlayout/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Eclipse project files
30 | .classpath
31 | .project
32 | project.properties
33 |
34 | # IDEA project files
35 | *.iml
36 | .idea/
37 |
38 | # OS generated files
39 | .DS_Store
40 | .DS_Store?
41 | ._*
42 | .Spotlight-V100
43 | .Trashes
44 | ehthumbs.db
45 | Thumbs.db
46 |
47 | # others
48 | ant.properties
49 | build.xml
50 | map.txt
51 |
--------------------------------------------------------------------------------
/fluidlayout/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | apply plugin: 'com.github.dcendents.android-maven'
4 | apply plugin: 'com.jfrog.bintray'
5 |
6 | def siteUrl = 'https://github.com/ifynn/FluidLayout'
7 | def gitUrl = 'https://github.com/ifynn/FluidLayout.git'
8 | group = "com.fynn.fluidlayout"
9 | version = "1.0"
10 |
11 | android {
12 | compileSdkVersion 23
13 | buildToolsVersion "23.0.3"
14 |
15 | defaultConfig {
16 | minSdkVersion 9
17 | targetSdkVersion 23
18 | versionCode 20160521
19 | versionName "1.0"
20 | }
21 | }
22 |
23 | install {
24 | repositories.mavenInstaller {
25 | // This generates POM.xml with proper parameters
26 | pom {
27 | project {
28 | packaging 'aar'
29 | name 'fluidLayout'
30 | description 'A Fluid Layout for Android'
31 | // #CONFIG# // project title
32 | url siteUrl
33 | // Set your license
34 | licenses {
35 | license {
36 | name 'The Apache Software License, Version 2.0'
37 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
38 | }
39 | }
40 | developers {
41 | developer {
42 | id 'fynn'
43 | // #CONFIG# // your user id (you can write your nickname)
44 | name 'fynn'
45 | // #CONFIG# // your user name
46 | email 'ifynn@outlook.com'
47 | // #CONFIG# // your email
48 | }
49 | }
50 | scm {
51 | connection gitUrl
52 | developerConnection gitUrl
53 | url siteUrl
54 | }
55 | }
56 | }
57 | }
58 | }
59 |
60 | task sourcesJar(type: Jar) {
61 | from android.sourceSets.main.java.srcDirs
62 | classifier = 'sources'
63 | }
64 |
65 | task javadoc(type: Javadoc) {
66 | options.encoding = "UTF-8"
67 | source = android.sourceSets.main.java.srcDirs
68 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
69 | }
70 |
71 | task javadocJar(type: Jar, dependsOn: javadoc) {
72 | classifier = 'javadoc'
73 | from javadoc.destinationDir
74 | }
75 |
76 | artifacts {
77 | archives javadocJar
78 | archives sourcesJar
79 | }
80 |
81 | Properties properties = new Properties()
82 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
83 | bintray {
84 | user = properties.getProperty("bintray.user")
85 | key = properties.getProperty("bintray.apikey")
86 | configurations = ['archives']
87 | pkg {
88 | repo = "maven"
89 | name = "fluidLayout"
90 | // #CONFIG# project name in jcenter
91 | websiteUrl = siteUrl
92 | vcsUrl = gitUrl
93 | licenses = ["Apache-2.0"]
94 | publish = true
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/fluidlayout/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 /Applications/adt-bundle/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 |
--------------------------------------------------------------------------------
/fluidlayout/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/fluidlayout/src/main/java/com/fynn/fluidlayout/FluidLayout.java:
--------------------------------------------------------------------------------
1 | package com.fynn.fluidlayout;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.util.AttributeSet;
6 | import android.view.Gravity;
7 | import android.view.View;
8 | import android.view.ViewDebug;
9 | import android.view.ViewGroup;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by fynn on 16/5/21.
16 | */
17 | public class FluidLayout extends ViewGroup {
18 |
19 | @ViewDebug.ExportedProperty(category = "measurement", flagMapping = {
20 | @ViewDebug.FlagToString(mask = Gravity.TOP,
21 | equals = Gravity.TOP, name = "TOP"),
22 | @ViewDebug.FlagToString(mask = Gravity.BOTTOM,
23 | equals = Gravity.BOTTOM, name = "BOTTOM"),
24 | @ViewDebug.FlagToString(mask = Gravity.CENTER,
25 | equals = Gravity.CENTER, name = "CENTER")
26 | }, formatToHexString = true)
27 | private int mGravity = Gravity.TOP;
28 |
29 | private List> mViews = new ArrayList>();
30 | private List mLineHeight = new ArrayList();
31 |
32 | public FluidLayout(Context context) {
33 | this(context, null);
34 | }
35 |
36 | public FluidLayout(Context context, AttributeSet attrs) {
37 | this(context, attrs, 0);
38 | }
39 |
40 | public FluidLayout(Context context, AttributeSet attrs, int defStyleAttr) {
41 | super(context, attrs, defStyleAttr);
42 |
43 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FluidLayout);
44 | int index = a.getInt(R.styleable.FluidLayout_gravity, -1);
45 | if (index >= 0) {
46 | setGravity(index);
47 | }
48 | a.recycle();
49 |
50 | }
51 |
52 | @Override
53 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
54 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
55 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
56 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
57 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
58 |
59 | int width = 0;
60 | int height = 0;
61 |
62 | int lineWidth = 0;
63 | int lineHeight = 0;
64 |
65 | int count = getChildCount();
66 | for (int i = 0; i < count; i++) {
67 | View child = getChildAt(i);
68 | if (child.getVisibility() == GONE) {
69 | continue;
70 | }
71 | measureChild(child, widthMeasureSpec, heightMeasureSpec);
72 | LayoutParams lp = (LayoutParams) child.getLayoutParams();
73 |
74 | int childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
75 | int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
76 |
77 | if (lineWidth + childWidth > widthSize - getPaddingLeft() - getPaddingRight()) {
78 | width = Math.max(width, lineWidth);
79 | lineWidth = childWidth;
80 | height += lineHeight;
81 | lineHeight = childHeight;
82 | } else {
83 | lineWidth += childWidth;
84 | lineHeight = Math.max(lineHeight, childHeight);
85 | }
86 |
87 | if (i == count - 1) {
88 | width = Math.max(lineWidth, width);
89 | height += lineHeight;
90 | }
91 | }
92 |
93 | setMeasuredDimension(
94 | widthMode == MeasureSpec.EXACTLY ? widthSize : width + getPaddingLeft() + getPaddingRight(),
95 | heightMode == MeasureSpec.EXACTLY ? heightSize : height + getPaddingTop() + getPaddingBottom()
96 | );
97 | }
98 |
99 | @Override
100 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
101 | mViews.clear();
102 | mLineHeight.clear();
103 |
104 | int width = getWidth();
105 | int lineWidth = 0;
106 | int lineHeight = 0;
107 |
108 | List lineViews = new ArrayList();
109 | int count = getChildCount();
110 |
111 | for (int i = 0; i < count; i++) {
112 | View child = getChildAt(i);
113 | LayoutParams lp = (LayoutParams) child.getLayoutParams();
114 |
115 | int childWidth = child.getMeasuredWidth();
116 | int childHeight = child.getMeasuredHeight();
117 |
118 | if (childWidth + lineWidth + lp.leftMargin + lp.rightMargin > width - getPaddingLeft() - getPaddingRight()) {
119 | mLineHeight.add(lineHeight);
120 | mViews.add(lineViews);
121 |
122 | lineWidth = 0;
123 | lineHeight = childHeight + lp.topMargin + lp.bottomMargin;
124 | lineViews = new ArrayList();
125 | }
126 |
127 | lineWidth += childWidth + lp.leftMargin + lp.rightMargin;
128 | lineHeight = Math.max(lineHeight, childHeight + lp.topMargin + lp.bottomMargin);
129 | lineViews.add(child);
130 | }
131 |
132 | //记录每行高度,为后面设置子view单独top做准备,比如gravity
133 | mLineHeight.add(lineHeight);
134 | mViews.add(lineViews);
135 |
136 | int left = getPaddingLeft();
137 | int top = getPaddingTop();
138 |
139 | int lineCount = mViews.size();
140 |
141 | for (int i = 0; i < lineCount; i++) {
142 | lineViews = mViews.get(i);
143 | lineHeight = mLineHeight.get(i);
144 | int lineViewCount = lineViews.size();
145 |
146 | for (int j = 0; j < lineViewCount; j++) {
147 | View child = lineViews.get(j);
148 | if (child.getVisibility() == GONE) {
149 | continue;
150 | }
151 |
152 | LayoutParams lp = (LayoutParams) child.getLayoutParams();
153 | int gravity = lp.gravity;
154 | if (gravity < 0) {
155 | gravity = mGravity;
156 | }
157 |
158 | int tmpTop = top;
159 | if (gravity == Gravity.CENTER) {
160 | tmpTop = top + (lineHeight - lp.topMargin - lp.bottomMargin - child.getMeasuredHeight()) / 2;
161 | } else if (gravity == Gravity.BOTTOM) {
162 | tmpTop = top + (lineHeight - lp.topMargin - lp.bottomMargin - child.getMeasuredHeight());
163 | }
164 |
165 | int lv = left + lp.leftMargin;
166 | int tv = tmpTop + lp.topMargin;
167 | int rv = lv + child.getMeasuredWidth();
168 | int bv = tv + child.getMeasuredHeight();
169 |
170 | child.layout(lv, tv, rv, bv);
171 |
172 | left += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
173 | }
174 |
175 | left = getPaddingLeft();
176 | top += lineHeight;
177 | }
178 | }
179 |
180 | public void setGravity(int gravity) {
181 | if (mGravity != gravity) {
182 | mGravity = gravity;
183 | requestLayout();
184 | }
185 | }
186 |
187 | @Override
188 | protected LayoutParams generateDefaultLayoutParams() {
189 | return new LayoutParams(
190 | LayoutParams.WRAP_CONTENT,
191 | LayoutParams.WRAP_CONTENT
192 | );
193 | }
194 |
195 | @Override
196 | public LayoutParams generateLayoutParams(AttributeSet attrs) {
197 | return new LayoutParams(getContext(), attrs);
198 | }
199 |
200 | @Override
201 | protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
202 | return new LayoutParams(p);
203 | }
204 |
205 | public static class LayoutParams extends ViewGroup.MarginLayoutParams {
206 |
207 | @ViewDebug.ExportedProperty(category = "layout", mapping = {
208 | @ViewDebug.IntToString(from = Gravity.TOP, to = "TOP"),
209 | @ViewDebug.IntToString(from = Gravity.BOTTOM, to = "BOTTOM"),
210 | @ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER")
211 | })
212 | public int gravity = -1;
213 |
214 | public LayoutParams(Context c, AttributeSet attrs) {
215 | super(c, attrs);
216 |
217 | TypedArray a =
218 | c.obtainStyledAttributes(attrs, R.styleable.FluidLayout_Layout);
219 | gravity = a.getInt(R.styleable.FluidLayout_Layout_layout_gravity, -1);
220 | a.recycle();
221 | }
222 |
223 | public LayoutParams(int width, int height) {
224 | super(width, height);
225 | }
226 |
227 | public LayoutParams(MarginLayoutParams source) {
228 | super(source);
229 | }
230 |
231 | public LayoutParams(ViewGroup.LayoutParams source) {
232 | super(source);
233 | }
234 |
235 | public LayoutParams(LayoutParams source) {
236 | super(source);
237 | this.gravity = source.gravity;
238 | }
239 | }
240 | }
241 |
--------------------------------------------------------------------------------
/fluidlayout/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/fluidlayout/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FluidLayout
3 |
4 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ifynn/FluidLayout/4fa489d7e0a4b13694d8df8f1dcb3d4f1f7c385e/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 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Eclipse project files
30 | .classpath
31 | .project
32 | project.properties
33 |
34 | # IDEA project files
35 | *.iml
36 | .idea/
37 |
38 | # OS generated files
39 | .DS_Store
40 | .DS_Store?
41 | ._*
42 | .Spotlight-V100
43 | .Trashes
44 | ehthumbs.db
45 | Thumbs.db
46 |
47 | # others
48 | ant.properties
49 | build.xml
50 | map.txt
51 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.fynn.fluidlayout.sample"
9 | minSdkVersion 9
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
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:appcompat-v7:23.2.1'
25 | compile project(':fluidlayout')
26 | compile 'com.android.support:design:23.2.1'
27 | }
28 |
--------------------------------------------------------------------------------
/sample/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 /Applications/adt-bundle/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 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/fynn/fluidlayout/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.fynn.fluidlayout.sample;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.Gravity;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.CompoundButton;
11 | import android.widget.TextView;
12 | import android.widget.ToggleButton;
13 |
14 | import com.fynn.fluidlayout.FluidLayout;
15 |
16 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
17 |
18 | private FluidLayout fluidLayout;
19 | private Button btnCenter;
20 | private Button btnBtm;
21 | private Button btnTop;
22 | private Button btnNormal;
23 | private ToggleButton btnStroke;
24 |
25 | private String[] tags = new String[]{
26 | "倩女幽魂", "单机斗地主", "天堂战记", "妖精的尾巴", "极限挑战", "我们相爱吧", "倚天屠龙记",
27 | "明星大侦探", "丰乳肥臀", "大主宰", "盗墓笔记", "鬼吹灯", "盘龙", "完美世界", "柠檬初上", "WIFI",
28 | "锁屏", "异术超能", "东方不败", "巅峰战舰", "小说", "污", "蒲公英", "网红", "霍建华", "林心如",
29 | "南极", "Java", "Android", "谷歌", "手机", "iPad", "充电宝", "黔驴技穷", "水果", "植物大战僵尸",
30 | "倩女幽魂", "单机斗地主", "天堂战记", "妖精的尾巴", "极限挑战", "我们相爱吧", "倚天屠龙记",
31 | "切水果", "手机", "iPad", "充电宝", "黔驴技穷", "水果", "植物大战僵尸", "切水果", "手机", "iPad",
32 | "充电宝", "黔驴技穷", "水果", "植物大战僵尸", "切水果", "手机", "iPad", "充电宝", "黔驴技穷",
33 | "水果", "植物大战僵尸", "切水果", "手机", "iPad", "充电宝", "黔驴技穷", "水果", "植物大战僵尸",
34 | "切水果", "手机", "iPad", "充电宝", "黔驴技穷", "水果", "植物大战僵尸", "切水果", "手机", "iPad",
35 | "充电宝", "黔驴技穷", "水果", "植物大战僵尸", "切水果", "手机", "iPad", "充电宝", "黔驴技穷",
36 | "水果", "植物大战僵尸", "切水果", "植物大战僵尸", "切水果", "植物大战僵尸", "切水果", "切水果",
37 | "充电宝", "黔驴技穷", "水果", "植物大战僵尸", "切水果", "手机", "iPad", "充电宝", "黔驴技穷",
38 | "倩女幽魂", "单机斗地主", "天堂战记", "妖精的尾巴", "极限挑战", "我们相爱吧", "倚天屠龙记",
39 | "水果", "植物大战僵尸", "切水果", "手机", "iPad", "充电宝", "黔驴技穷", "水果", "植物大战僵尸",
40 | "切水果", "手机", "iPad", "充电宝", "黔驴技穷", "水果", "植物大战僵尸", "切水果", "手机", "iPad",
41 | "充电宝", "黔驴技穷", "水果", "植物大战僵尸", "切水果", "手机", "iPad", "充电宝", "黔驴技穷",
42 | "水果", "植物大战僵尸", "切水果", "植物大战僵尸", "切水果", "植物大战僵尸", "切水果", "切水果"};
43 |
44 | private int gravity = Gravity.TOP;
45 | private boolean hasBg = true;
46 | private boolean isNormal = true;
47 |
48 | @Override
49 | protected void onCreate(Bundle savedInstanceState) {
50 | super.onCreate(savedInstanceState);
51 | setContentView(R.layout.activity_main);
52 |
53 | fluidLayout = (FluidLayout) findViewById(R.id.fluid_layout);
54 | btnCenter = (Button) findViewById(R.id.btn_center);
55 | btnBtm = (Button) findViewById(R.id.btn_btm);
56 | btnTop = (Button) findViewById(R.id.btn_top);
57 | btnStroke = (ToggleButton) findViewById(R.id.btn_stroke);
58 | btnNormal = (Button) findViewById(R.id.btn_normal);
59 |
60 | btnTop.setOnClickListener(this);
61 | btnBtm.setOnClickListener(this);
62 | btnCenter.setOnClickListener(this);
63 | btnNormal.setOnClickListener(this);
64 |
65 | btnStroke.setChecked(hasBg);
66 |
67 | btnStroke.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
68 | @Override
69 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
70 | hasBg = isChecked;
71 | genTag(hasBg);
72 | }
73 | });
74 |
75 | genTag(true);
76 | }
77 |
78 | @Override
79 | public void onClick(View v) {
80 | if (v == btnTop) {
81 | gravity = Gravity.TOP;
82 | isNormal = false;
83 | genTag(hasBg);
84 |
85 | } else if (v == btnCenter) {
86 | gravity = Gravity.CENTER;
87 | isNormal = false;
88 | genTag(hasBg);
89 |
90 | } else if (v == btnBtm) {
91 | gravity = Gravity.BOTTOM;
92 | isNormal = false;
93 | genTag(hasBg);
94 |
95 | } else if (v == btnNormal) {
96 | isNormal = !isNormal;
97 | genTag(hasBg);
98 | }
99 | }
100 |
101 | private void genTag(boolean hasBg) {
102 | fluidLayout.removeAllViews();
103 | fluidLayout.setGravity(gravity);
104 | for (int i = 0; i < tags.length; i++) {
105 | TextView tv = new TextView(this);
106 | tv.setText(tags[i]);
107 | tv.setTextSize(13);
108 |
109 | if (i == 12) {
110 | if (!isNormal) {
111 | tv.setHeight(100);
112 | tv.setGravity(Gravity.CENTER);
113 | }
114 | tv.setBackgroundResource(R.drawable.text_bg_highlight);
115 |
116 | } else {
117 | if (hasBg) {
118 | tv.setBackgroundResource(R.drawable.text_bg);
119 | }
120 | }
121 |
122 | if (i % 8 == 0) {
123 | tv.setTextColor(Color.parseColor("#FF0000"));
124 | } else if (i % 28 == 0) {
125 | tv.setTextColor(Color.parseColor("#66CD00"));
126 | } else {
127 | tv.setTextColor(Color.parseColor("#666666"));
128 | }
129 |
130 | FluidLayout.LayoutParams params = new FluidLayout.LayoutParams(
131 | ViewGroup.LayoutParams.WRAP_CONTENT,
132 | ViewGroup.LayoutParams.WRAP_CONTENT
133 | );
134 | params.setMargins(12, 12, 12, 12);
135 | fluidLayout.addView(tv, params);
136 | }
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/text_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
12 |
15 |
16 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/text_bg_highlight.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
12 |
15 |
16 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
21 |
22 |
23 |
24 |
27 |
28 |
33 |
34 |
43 |
44 |
53 |
54 |
63 |
64 |
73 |
74 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ifynn/FluidLayout/4fa489d7e0a4b13694d8df8f1dcb3d4f1f7c385e/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ifynn/FluidLayout/4fa489d7e0a4b13694d8df8f1dcb3d4f1f7c385e/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ifynn/FluidLayout/4fa489d7e0a4b13694d8df8f1dcb3d4f1f7c385e/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ifynn/FluidLayout/4fa489d7e0a4b13694d8df8f1dcb3d4f1f7c385e/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ifynn/FluidLayout/4fa489d7e0a4b13694d8df8f1dcb3d4f1f7c385e/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FluidLayout
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':fluidlayout'
2 |
--------------------------------------------------------------------------------
/snapshot/demo_gif.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ifynn/FluidLayout/4fa489d7e0a4b13694d8df8f1dcb3d4f1f7c385e/snapshot/demo_gif.gif
--------------------------------------------------------------------------------
/snapshot/snapshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ifynn/FluidLayout/4fa489d7e0a4b13694d8df8f1dcb3d4f1f7c385e/snapshot/snapshot.png
--------------------------------------------------------------------------------