StackLayout now reduce available height by its padding

TextView is now remeasured so that it centers its text. This is needed because when its given more size in onLayout it won't center correctly.
This commit is contained in:
hshristov
2015-08-03 10:59:04 +03:00
parent 1299747cf6
commit c0d47c8c3f
2 changed files with 26 additions and 1 deletions

View File

@@ -124,6 +124,31 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams {
childLeft = Math.round(childLeft);
childTop = Math.round(childTop);
// Re-measure TextView because it is not centered if layout width is larger than measure width.
if (child instanceof android.widget.TextView) {
int measuredWidth = child.getMeasuredWidth();
int measuredHeight = child.getMeasuredHeight();
int width = right - left;
int height = bottom - top;
if (Math.abs(measuredWidth - width) > 1 || Math.abs(measuredHeight - height) > 1) {
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
if (debuggable > 0) {
sb.setLength(0);
sb.append("remeasure ");
sb.append(child);
sb.append(" with ");
sb.append(MeasureSpec.toString(widthMeasureSpec));
sb.append(", ");
sb.append(MeasureSpec.toString(heightMeasureSpec));
log(tag, sb.toString());
}
child.measure(widthMeasureSpec, heightMeasureSpec);
}
}
if (debuggable > 0) {
sb.setLength(0);
sb.append(child.getParent().toString());

View File

@@ -87,7 +87,7 @@ public class StackLayout extends LayoutBase {
remainingLength = Math.max(0, remainingLength - childMeasuredHeight);
}
else {
CommonLayoutParams.measureChild(child, MeasureSpec.makeMeasureSpec(remainingLength, measureSpecMode), heightMeasureSpec);
CommonLayoutParams.measureChild(child, MeasureSpec.makeMeasureSpec(remainingLength, measureSpecMode), childMeasureSpec);
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);