Skip to content

Commit 239416e

Browse files
author
Guillaume Boudreau
committed
Merge branch 'master' of github.com:ApmeM/android-flowlayout
Conflicts: .gitignore
2 parents d747e9d + 3391db7 commit 239416e

36 files changed

+1128
-498
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ target/
55
*.log
66
*.class
77
.idea/
8+
.gradle
9+
build/
10+
*.orig
811
libraries/layouts/src/android-flowlayout/gen
912
libraries/layouts/src/android-flowlayout/bin

README.md

+57-24
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,47 @@
44

55
Extended linear layout that wrap its content when there is no place in the current line.
66

7+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apmem.tools/layouts/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/org.apmem.tools/layouts/)
8+
79
## Demonstration
810

9-
Horizontal:
11+
Orientation: HORIZONTAL, Gravity: FILL, LayoutDirection: LTR
12+
13+
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/LANDSCAPE_LTR_FILL_HORIZONTAL_DEBUG.png)
14+
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/PORTRAIT_LTR_FILL_HORIZONTAL_DEBUG.png)
15+
16+
Orientation: HORIZONTAL, Gravity: RIGHT & BOTTOM, LayoutDirection: RTL
1017

11-
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/horizontal_portrait.png)
12-
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/horizontal_album.png)
18+
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/LANDSCAPE_RTL_RIGHTBOTTOM_HORIZONTAL_DEBUG.png)
19+
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/PORTRAIT_RTL_RIGHTBOTTOM_HORIZONTAL_DEBUG.png)
1320

14-
Vertical:
21+
Orientation: VERTICAL, Gravity: CENTER, LayoutDirection: LTR
1522

16-
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/vertical_portrait.png)
17-
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/vertical_album.png)
23+
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/LANDSCAPE_LTR_CENTER_VERTICAL_DEBUG.png)
24+
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/PORTRAIT_LTR_CENTER_VERTICAL_DEBUG.png)
1825

1926
Debug is switched off:
2027

21-
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/no_debug.png)
28+
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/LANDSCAPE_LTR_FILL_HORIZONTAL_NODEBUG.png)
29+
![](https://github.com/ApmeM/android-flowlayout/raw/master/img/PORTRAIT_LTR_FILL_HORIZONTAL_NODEBUG.png)
2230

2331
## Installation and usage
2432

2533
Take from maven repository (<http://search.maven.org/#search%7Cga%7C1%7Corg.apmem.tools>, <http://mvnrepository.com/search.html?query=org.apmem.tools>) or add FlowLayout and other components to your solution
2634

35+
Add it as dependency in Gradle as:
36+
37+
compile 'org.apmem.tools:layouts:1.8@aar'
38+
39+
Or maven
40+
41+
<dependency>
42+
<groupId>org.apmem.tools</groupId>
43+
<artifactId>layouts</artifactId>
44+
<version>1.8</version>
45+
<scope>provided</scope>
46+
</dependency>
47+
2748
Add the following xml code into your layout/something.xml:
2849

2950
<org.apmem.tools.layouts.FlowLayout
@@ -33,20 +54,24 @@ Add the following xml code into your layout/something.xml:
3354
>
3455
</org.apmem.tools.layouts.FlowLayout>
3556

36-
To change default horizontal and vertical spacing between elements in layout use the following code:
37-
38-
xmlns:f="http://schemas.android.com/apk/res/your.namespace"
39-
f:horizontalSpacing="6dip"
40-
f:verticalSpacing="12dip"
41-
4257
To change default direction use the following code
4358

44-
f:orientation="vertical"
59+
android:orientation="vertical"
4560

46-
To override default spacing use the following LayoutParameter in the child View element:
61+
To change layout direction use the following code
62+
63+
xmlns:f="http://schemas.android.com/apk/res/your.namespace"
64+
f:layoutDirection="rtl"
65+
66+
Android gravity now supported (in combination with elements weight):
4767

48-
f:layout_horizontalSpacing="32dip"
49-
f:layout_verticalSpacing="32dip"
68+
f:weightDefault="1.0"
69+
android:gravity="fill"
70+
71+
To override default spacing between elements use default android margins in the child View element:
72+
73+
android:layout_marginTop="32dip"
74+
android:layout_marginRight="32dip"
5075

5176
Also if you need to break line before some object even if there is enough space for it in the previous line - use the following LayoutParameter in the child view element:
5277

@@ -56,23 +81,31 @@ Also if you need to break line before some object even if there is enough space
5681

5782
Layout parameters:
5883

59-
* horizontalSpacing - default horizontal spacing between elements
84+
* android:orientation - line direction. Use one of the following values:
85+
86+
* horizontal - line will be in horizontal direction, linebreak will create new line
87+
88+
* vertical - line will be in vertical direction, linebreak will create new column
6089

61-
* verticalSpacing - default vertical spacing between elements
90+
* android:gravity - standart android gravity supported
6291

6392
* debugDraw - draw debug information
6493

65-
* orientation - line direction. Use one of the following values:
94+
* weightDefault - default weight value for child elements. Used to fill line in case of Gravity.FILL_HORIZONTAL | Gravity.FILL_VERTICAL
6695

67-
* horizontal - line will be in horizontal direction, linebreak will create new line
96+
* layoutDirection - direction of inner child elements:
6897

69-
* vertical - line will be in vertical direction, linebreak will create new column
98+
* ltr - left to right direction
99+
100+
* rtl - right to left direction
70101

71102
Child layout parameters:
72103

73-
* layout_horizontalSpacing - override default horizontal spacing
104+
* android:layout_margin* - override default spacings
105+
106+
* android:layout_gravity - standart aandroid gravity supported
74107

75-
* layout_verticalSpacing - override default vertical spacing
108+
* layout_weight - weight of the element. If not specified "layout.defaultWight" is used.
76109

77110
* layout_newLine - brake line before current element even if there is enough place in the current line.
78111

app/build.gradle

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apply plugin: 'com.android.application'
2+
3+
dependencies {
4+
compile project(':libraries:layouts')
5+
}
6+
7+
version = VERSION_NAME
8+
group = GROUP
9+
10+
android {
11+
compileSdkVersion 10
12+
buildToolsVersion '19.1.0'
13+
14+
defaultConfig {
15+
versionName project.VERSION_NAME
16+
versionCode Integer.parseInt(project.VERSION_CODE)
17+
}
18+
}

app/pom.xml

-57
This file was deleted.

app/src/main/java/org/apmem/tools/example/MyActivity.java

+78-13
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import android.app.Activity;
44
import android.os.Bundle;
5-
import android.widget.LinearLayout;
6-
import android.widget.TextView;
5+
import android.view.Gravity;
6+
import android.view.View;
7+
import android.widget.Button;
78
import org.apmem.tools.layouts.FlowLayout;
89

910
public class MyActivity extends Activity {
@@ -15,18 +16,82 @@ public void onCreate(Bundle savedInstanceState) {
1516
super.onCreate(savedInstanceState);
1617
setContentView(R.layout.main);
1718

18-
FlowLayout layout = (FlowLayout)this.findViewById(R.id.flowLayout);
19+
final FlowLayout layout = (FlowLayout) this.findViewById(R.id.flowLayout);
1920

20-
TextView textView;
21-
textView = new TextView(this);
22-
textView.setLayoutParams(new FlowLayout.LayoutParams(100, 100));
23-
textView.setTextAppearance(this, android.R.style.TextAppearance_Large);
24-
textView.setText("appearance");
25-
layout.addView(textView, 0);
21+
final Button buttonOrientation = new Button(this);
22+
buttonOrientation.setLayoutParams(new FlowLayout.LayoutParams(100, 100));
23+
buttonOrientation.setTextSize(8);
24+
buttonOrientation.setText("Switch Orientation (Current: Horizontal)");
25+
buttonOrientation.setOnClickListener(new View.OnClickListener() {
26+
@Override
27+
public void onClick(View view) {
28+
layout.setOrientation(1 - layout.getOrientation());
29+
buttonOrientation.setText(layout.getOrientation() == FlowLayout.HORIZONTAL ?
30+
"Switch Orientation (Current: Horizontal)" :
31+
"Switch Orientation (Current: Vertical)");
32+
}
33+
});
34+
layout.addView(buttonOrientation, 0);
2635

27-
textView = new TextView(this);
28-
textView.setLayoutParams(new FlowLayout.LayoutParams(100, 100));
29-
textView.setText("appearance");
30-
layout.addView(textView, 0);
36+
final Button buttonGravity = new Button(this);
37+
buttonGravity.setLayoutParams(new FlowLayout.LayoutParams(100, 100));
38+
buttonGravity.setTextSize(8);
39+
buttonGravity.setText("Switch Gravity (Current: FILL)");
40+
buttonGravity.setOnClickListener(new View.OnClickListener() {
41+
@Override
42+
public void onClick(View view) {
43+
switch (layout.getGravity()) {
44+
case Gravity.LEFT | Gravity.TOP:
45+
layout.setGravity(Gravity.FILL);
46+
buttonGravity.setText("Switch Gravity (Current: FILL)");
47+
break;
48+
case Gravity.FILL:
49+
layout.setGravity(Gravity.CENTER);
50+
buttonGravity.setText("Switch Gravity (Current: CENTER)");
51+
break;
52+
case Gravity.CENTER:
53+
layout.setGravity(Gravity.RIGHT | Gravity.BOTTOM);
54+
buttonGravity.setText("Switch Gravity (Current: RIGHT | BOTTOM)");
55+
break;
56+
case Gravity.RIGHT | Gravity.BOTTOM:
57+
layout.setGravity(Gravity.LEFT | Gravity.TOP);
58+
buttonGravity.setText("Switch Gravity (Current: LEFT | TOP)");
59+
break;
60+
}
61+
}
62+
});
63+
layout.addView(buttonGravity, 0);
64+
65+
final Button buttonLayoutDirection = new Button(this);
66+
buttonLayoutDirection.setLayoutParams(new FlowLayout.LayoutParams(100, 100));
67+
buttonLayoutDirection.setTextSize(8);
68+
buttonLayoutDirection.setText("Switch LayoutDirection (Current: LTR)");
69+
buttonLayoutDirection.setOnClickListener(new View.OnClickListener() {
70+
@Override
71+
public void onClick(View view) {
72+
layout.setLayoutDirection(1 - layout.getLayoutDirection());
73+
buttonLayoutDirection.setText(layout.getLayoutDirection() == FlowLayout.LAYOUT_DIRECTION_LTR ?
74+
"Switch LayoutDirection (Current: LTR)" :
75+
"Switch LayoutDirection (Current: RTL)");
76+
}
77+
78+
});
79+
layout.addView(buttonLayoutDirection, 0);
80+
81+
final Button buttonDebug = new Button(this);
82+
buttonDebug.setLayoutParams(new FlowLayout.LayoutParams(100, 100));
83+
buttonDebug.setTextSize(8);
84+
buttonDebug.setText("Switch Debug (Current: true)");
85+
buttonDebug.setOnClickListener(new View.OnClickListener() {
86+
@Override
87+
public void onClick(View view) {
88+
layout.setDebugDraw(!layout.isDebugDraw());
89+
buttonDebug.setText(layout.isDebugDraw() ?
90+
"Switch LayoutDirection (Current: true)" :
91+
"Switch LayoutDirection (Current: false)");
92+
}
93+
94+
});
95+
layout.addView(buttonDebug, 0);
3196
}
3297
}

0 commit comments

Comments
 (0)