Fix RTL space to fit screen
This commit is contained in:
parent
7a738dd55c
commit
cbc77377cb
1 changed files with 23 additions and 17 deletions
|
@ -15,17 +15,17 @@ public class FlowLayout extends ViewGroup {
|
||||||
|
|
||||||
final int horizontal_spacing;
|
final int horizontal_spacing;
|
||||||
final int vertical_spacing;
|
final int vertical_spacing;
|
||||||
final boolean horizontalAutoSpacing;
|
final boolean isHorizontalAutoSpacing;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param horizontal_spacing Pixels between items, horizontally
|
* @param horizontal_spacing Pixels between items, horizontally
|
||||||
* @param vertical_spacing Pixels between items, vertically
|
* @param vertical_spacing Pixels between items, vertically
|
||||||
*/
|
*/
|
||||||
public LayoutParams(int horizontal_spacing, int vertical_spacing, boolean horizontalAutoSpacing) {
|
public LayoutParams(int horizontal_spacing, int vertical_spacing, boolean isHorizontalAutoSpacing) {
|
||||||
super(0, 0);
|
super(0, 0);
|
||||||
this.horizontal_spacing = horizontal_spacing;
|
this.horizontal_spacing = horizontal_spacing;
|
||||||
this.vertical_spacing = vertical_spacing;
|
this.vertical_spacing = vertical_spacing;
|
||||||
this.horizontalAutoSpacing = horizontalAutoSpacing;
|
this.isHorizontalAutoSpacing = isHorizontalAutoSpacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,19 +48,19 @@ public class FlowLayout extends ViewGroup {
|
||||||
int line_height = 0;
|
int line_height = 0;
|
||||||
int horizontalPosition = getPaddingLeft();
|
int horizontalPosition = getPaddingLeft();
|
||||||
int verticalPosition = getPaddingTop();
|
int verticalPosition = getPaddingTop();
|
||||||
int childHeighteightMeasureSpec;
|
int childHeightMeasureSpec;
|
||||||
|
|
||||||
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
|
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
|
||||||
childHeighteightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
|
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
|
||||||
} else {
|
} else {
|
||||||
childHeighteightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
final View child = getChildAt(i);
|
final View child = getChildAt(i);
|
||||||
if (child.getVisibility() != GONE) {
|
if (child.getVisibility() != GONE) {
|
||||||
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
|
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
|
||||||
child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), childHeighteightMeasureSpec);
|
child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), childHeightMeasureSpec);
|
||||||
final int childWidth = child.getMeasuredWidth();
|
final int childWidth = child.getMeasuredWidth();
|
||||||
line_height = Math.max(line_height, child.getMeasuredHeight() + lp.vertical_spacing);
|
line_height = Math.max(line_height, child.getMeasuredHeight() + lp.vertical_spacing);
|
||||||
if (horizontalPosition + childWidth > width) {
|
if (horizontalPosition + childWidth > width) {
|
||||||
|
@ -112,28 +112,34 @@ public class FlowLayout extends ViewGroup {
|
||||||
} else {
|
} else {
|
||||||
freeSizeSpacing = width % childWidth / itemsCount;
|
freeSizeSpacing = width % childWidth / itemsCount;
|
||||||
}
|
}
|
||||||
if (isLayoutRtl) {
|
if (isLayoutRtl && lp.isHorizontalAutoSpacing) {
|
||||||
|
if (horizontalPosition - childWidth < getPaddingLeft()) {
|
||||||
|
horizontalPosition = width - getPaddingRight();
|
||||||
|
verticalPosition += line_height;
|
||||||
|
}
|
||||||
|
child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight);
|
||||||
|
horizontalPosition -= childWidth + lp.horizontal_spacing + freeSizeSpacing;
|
||||||
|
} else if (isLayoutRtl) {
|
||||||
if (horizontalPosition - childWidth < l) {
|
if (horizontalPosition - childWidth < l) {
|
||||||
horizontalPosition = width - getPaddingRight();
|
horizontalPosition = width - getPaddingRight();
|
||||||
verticalPosition += line_height;
|
verticalPosition += line_height;
|
||||||
}
|
}
|
||||||
child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight);
|
child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight);
|
||||||
if (lp.horizontalAutoSpacing) {
|
horizontalPosition -= childWidth + lp.horizontal_spacing;
|
||||||
horizontalPosition -= childWidth + lp.horizontal_spacing + freeSizeSpacing;
|
} else if (!lp.isHorizontalAutoSpacing) {
|
||||||
} else {
|
if (horizontalPosition + childWidth > width) {
|
||||||
horizontalPosition -= childWidth + lp.horizontal_spacing;
|
horizontalPosition = getPaddingLeft();
|
||||||
|
verticalPosition += line_height;
|
||||||
}
|
}
|
||||||
|
child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight);
|
||||||
|
horizontalPosition += childWidth + lp.horizontal_spacing;
|
||||||
} else {
|
} else {
|
||||||
if (horizontalPosition + childWidth > width) {
|
if (horizontalPosition + childWidth > width) {
|
||||||
horizontalPosition = getPaddingLeft();
|
horizontalPosition = getPaddingLeft();
|
||||||
verticalPosition += line_height;
|
verticalPosition += line_height;
|
||||||
}
|
}
|
||||||
child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight);
|
child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight);
|
||||||
if (lp.horizontalAutoSpacing) {
|
horizontalPosition += childWidth + lp.horizontal_spacing + freeSizeSpacing;
|
||||||
horizontalPosition += childWidth + lp.horizontal_spacing + freeSizeSpacing;
|
|
||||||
} else {
|
|
||||||
horizontalPosition += childWidth + lp.horizontal_spacing;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue