@@ -35,6 +35,10 @@ public class FlowLayout extends ViewGroup {
35
35
36
36
private int mGravity = Gravity .START | Gravity .TOP ;
37
37
38
+ List <List <View >> mLines = new ArrayList <List <View >>();
39
+ List <Integer > mLineHeights = new ArrayList <Integer >();
40
+ List <Integer > mLineMargins = new ArrayList <Integer >();
41
+
38
42
public FlowLayout (Context context ) {
39
43
super (context );
40
44
}
@@ -60,9 +64,9 @@ public FlowLayout(Context context, AttributeSet attrs, int defStyle) {
60
64
@ Override
61
65
protected void onLayout (boolean changed , int l , int t , int r , int b ) {
62
66
63
- List < List < View >> lines = new ArrayList < List < View >> ();
64
- List < Integer > lineHeights = new ArrayList < Integer > ();
65
- List < Integer > lineMargins = new ArrayList < Integer > ();
67
+ mLines . clear ();
68
+ mLineHeights . clear ();
69
+ mLineMargins . clear ();
66
70
67
71
int width = getWidth ();
68
72
int height = getHeight ();
@@ -100,9 +104,9 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
100
104
int childHeight = child .getMeasuredHeight () + lp .bottomMargin + lp .topMargin ;
101
105
102
106
if (lineWidth + childWidth > width ) {
103
- lineHeights .add (lineHeight );
104
- lines .add (lineViews );
105
- lineMargins .add ((int ) ((width - lineWidth ) * horizontalGravityFactor ));
107
+ mLineHeights .add (lineHeight );
108
+ mLines .add (lineViews );
109
+ mLineMargins .add ((int ) ((width - lineWidth ) * horizontalGravityFactor ));
106
110
107
111
linesSum += lineHeight ;
108
112
@@ -116,9 +120,9 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
116
120
lineViews .add (child );
117
121
}
118
122
119
- lineHeights .add (lineHeight );
120
- lines .add (lineViews );
121
- lineMargins .add ((int ) ((width - lineWidth ) * horizontalGravityFactor ));
123
+ mLineHeights .add (lineHeight );
124
+ mLines .add (lineViews );
125
+ mLineMargins .add ((int ) ((width - lineWidth ) * horizontalGravityFactor ));
122
126
123
127
linesSum += lineHeight ;
124
128
@@ -135,16 +139,16 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
135
139
break ;
136
140
}
137
141
138
- int numLines = lineHeights .size ();
142
+ int numLines = mLines .size ();
139
143
140
144
int left ;
141
145
int top = 0 ;
142
146
143
147
for (int i = 0 ; i < numLines ; i ++) {
144
148
145
- lineHeight = lineHeights .get (i );
146
- lineViews = lines .get (i );
147
- left = lineMargins .get (i );
149
+ lineHeight = mLineHeights .get (i );
150
+ lineViews = mLines .get (i );
151
+ left = mLineMargins .get (i );
148
152
149
153
int children = lineViews .size ();
150
154
0 commit comments