Fix layout positioning for Toolbar
Fix a bug where the starting position was not properly updated for the
previous view's measured width.
Bug 14900794
Change-Id: I6064c5353abc83159cd4c7d6ccfce64640735791
diff --git a/core/java/android/widget/Toolbar.java b/core/java/android/widget/Toolbar.java
index 075feba..928e34e 100644
--- a/core/java/android/widget/Toolbar.java
+++ b/core/java/android/widget/Toolbar.java
@@ -734,13 +734,13 @@
addCustomViewsWithGravity(mTempViews, Gravity.LEFT);
final int leftViewsCount = mTempViews.size();
for (int i = 0; i < leftViewsCount; i++) {
- left = layoutChildLeft(getChildAt(i), left);
+ left = layoutChildLeft(mTempViews.get(i), left);
}
addCustomViewsWithGravity(mTempViews, Gravity.RIGHT);
final int rightViewsCount = mTempViews.size();
for (int i = 0; i < rightViewsCount; i++) {
- right = layoutChildRight(getChildAt(i), right);
+ right = layoutChildRight(mTempViews.get(i), right);
}
// Centered views try to center with respect to the whole bar, but views pinned
@@ -759,7 +759,7 @@
final int centerViewsCount = mTempViews.size();
for (int i = 0; i < centerViewsCount; i++) {
- centerLeft = layoutChildLeft(getChildAt(i), centerLeft);
+ centerLeft = layoutChildLeft(mTempViews.get(i), centerLeft);
}
mTempViews.clear();
}
@@ -778,18 +778,20 @@
private int layoutChildLeft(View child, int left) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
left += lp.leftMargin;
- int top = getChildTop(child);
- child.layout(left, top, left + child.getMeasuredWidth(), top + child.getMeasuredHeight());
- left += lp.rightMargin;
+ final int top = getChildTop(child);
+ final int childWidth = child.getMeasuredWidth();
+ child.layout(left, top, left + childWidth, top + child.getMeasuredHeight());
+ left += childWidth + lp.rightMargin;
return left;
}
private int layoutChildRight(View child, int right) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
right -= lp.rightMargin;
- int top = getChildTop(child);
- child.layout(right - child.getMeasuredWidth(), top, right, top + child.getMeasuredHeight());
- right -= lp.leftMargin;
+ final int top = getChildTop(child);
+ final int childWidth = child.getMeasuredWidth();
+ child.layout(right - childWidth, top, right, top + child.getMeasuredHeight());
+ right -= childWidth + lp.leftMargin;
return right;
}