Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b606a3a3 authored by Adam Powell's avatar Adam Powell
Browse files

Measure Toolbar titles last

Give the maximum amount of room to "real" content views before taking
up space for the title and subtitle of a toolbar.

Bug 16039951

Change-Id: I10da9cdc39e84e6fb3975ee40958c57031002dd5
parent c80f9522
Loading
Loading
Loading
Loading
+15 −15
Original line number Diff line number Diff line
@@ -1161,6 +1161,21 @@ public class Toolbar extends ViewGroup {
            childState = combineMeasuredStates(childState, mLogoView.getMeasuredState());
        }

        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp.mViewType != LayoutParams.CUSTOM || !shouldLayout(child)) {
                // We already got all system views above. Skip them and GONE views.
                continue;
            }

            width += measureChildCollapseMargins(child, widthMeasureSpec, width,
                    heightMeasureSpec, 0, collapsingMargins);
            height = Math.max(height, child.getMeasuredHeight() + getVerticalMargins(child));
            childState = combineMeasuredStates(childState, child.getMeasuredState());
        }

        int titleWidth = 0;
        int titleHeight = 0;
        final int titleVertMargins = mTitleMarginTop + mTitleMarginBottom;
@@ -1186,21 +1201,6 @@ public class Toolbar extends ViewGroup {
        width += titleWidth;
        height = Math.max(height, titleHeight);

        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp.mViewType != LayoutParams.CUSTOM || !shouldLayout(child)) {
                // We already got all system views above. Skip them and GONE views.
                continue;
            }

            width += measureChildCollapseMargins(child, widthMeasureSpec, width,
                    heightMeasureSpec, 0, collapsingMargins);
            height = Math.max(height, child.getMeasuredHeight() + getVerticalMargins(child));
            childState = combineMeasuredStates(childState, child.getMeasuredState());
        }

        // Measurement already took padding into account for available space for the children,
        // add it in for the final size.
        width += getPaddingLeft() + getPaddingRight();