Improved performance in SquareGridLayout (#631)
This commit is contained in:
parent
cdbdd98d6a
commit
4dda3ac6e8
|
@ -87,13 +87,12 @@ public class SquareGridLayout extends ViewGroup {
|
||||||
int paddingHeight = getPaddingTop() + getPaddingBottom();
|
int paddingHeight = getPaddingTop() + getPaddingBottom();
|
||||||
|
|
||||||
int size;
|
int size;
|
||||||
int padding;
|
|
||||||
if ((width - paddingWidth) < (height - paddingHeight)) {
|
if ((width - paddingWidth) < (height - paddingHeight)) {
|
||||||
size = width;
|
size = width;
|
||||||
padding = size - paddingWidth;
|
cellSize = (size - paddingWidth) / columnCount;
|
||||||
} else {
|
} else {
|
||||||
size = height;
|
size = height;
|
||||||
padding = size - paddingHeight;
|
cellSize = (size - paddingHeight) / columnCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < columnCount; y++) {
|
for (int y = 0; y < columnCount; y++) {
|
||||||
|
@ -101,16 +100,15 @@ public class SquareGridLayout extends ViewGroup {
|
||||||
View child = getChildAt(y * size + x);
|
View child = getChildAt(y * size + x);
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
measureChildWithMargins(child,
|
measureChildWithMargins(child,
|
||||||
MeasureSpec.makeMeasureSpec((padding + x) / columnCount, MeasureSpec.EXACTLY),
|
MeasureSpec.makeMeasureSpec(cellSize, MeasureSpec.EXACTLY),
|
||||||
0,
|
0,
|
||||||
MeasureSpec.makeMeasureSpec((padding + y) / columnCount, MeasureSpec.EXACTLY),
|
MeasureSpec.makeMeasureSpec(cellSize, MeasureSpec.EXACTLY),
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setMeasuredDimension(size, size);
|
setMeasuredDimension(size, size);
|
||||||
cellSize = padding;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,10 +121,10 @@ public class SquareGridLayout extends ViewGroup {
|
||||||
for (int x = 0; x < columnCount; x++) {
|
for (int x = 0; x < columnCount; x++) {
|
||||||
View child = getChildAt(y * columnCount + x);
|
View child = getChildAt(y * columnCount + x);
|
||||||
MarginLayoutParams childLayoutParams = (MarginLayoutParams) child.getLayoutParams();
|
MarginLayoutParams childLayoutParams = (MarginLayoutParams) child.getLayoutParams();
|
||||||
child.layout(left + (cellSize * x) / columnCount + childLayoutParams.leftMargin,
|
child.layout(left + (cellSize * x) + childLayoutParams.leftMargin,
|
||||||
top + (cellSize * y) / columnCount + childLayoutParams.topMargin,
|
top + (cellSize * y) + childLayoutParams.topMargin,
|
||||||
left + (cellSize * (x+1)) / columnCount - childLayoutParams.rightMargin,
|
left + (cellSize * (x+1)) - childLayoutParams.rightMargin,
|
||||||
top + (cellSize * (y+1)) / columnCount - childLayoutParams.bottomMargin
|
top + (cellSize * (y+1)) - childLayoutParams.bottomMargin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue