Example usage for android.view View getMeasuredHeight

List of usage examples for android.view View getMeasuredHeight

Introduction

In this page you can find the example usage for android.view View getMeasuredHeight.

Prototype

public final int getMeasuredHeight() 

Source Link

Document

Like #getMeasuredHeightAndState() , but only returns the raw height component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

From source file:com.cxsplay.wallyskim.widget.flexbox.FlexboxLayout.java

/**
 * Expand the view horizontally to the size of the crossSize (considering the view margins)
 *
 * @param view      the View to be stretched
 * @param crossSize the cross size//  w w w.  jav  a 2s  .  c  o  m
 */
private void stretchViewHorizontally(View view, int crossSize) {
    LayoutParams lp = (LayoutParams) view.getLayoutParams();
    int newWidth = crossSize - lp.leftMargin - lp.rightMargin;
    newWidth = Math.max(newWidth, 0);
    view.measure(MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(view.getMeasuredHeight(), MeasureSpec.EXACTLY));
}

From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    if (widthMode != MeasureSpec.EXACTLY) {
        if (isInEditMode()) {
            if (widthMode == MeasureSpec.UNSPECIFIED) {
                widthSize = 300;/*from   ww w. j  a  va  2s.  c om*/
            }
        } else {
            throw new IllegalStateException("Width must have an exact value or MATCH_PARENT");
        }
    } else if (heightMode == MeasureSpec.UNSPECIFIED) {
        if (isInEditMode()) {
            if (heightMode == MeasureSpec.UNSPECIFIED) {
                heightMode = MeasureSpec.AT_MOST;
                heightSize = 300;
            }
        } else {
            throw new IllegalStateException("Height must not be UNSPECIFIED");
        }
    }

    int layoutHeight = 0;
    int maxLayoutHeight = -1;
    switch (heightMode) {
    case MeasureSpec.EXACTLY:
        layoutHeight = maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom();
        break;
    case MeasureSpec.AT_MOST:
        maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom();
        break;
    }

    float weightSum = 0;
    boolean canSlide = false;
    final int widthAvailable = widthSize - getPaddingLeft() - getPaddingRight();
    int widthRemaining = widthAvailable;
    final int childCount = getChildCount();

    if (childCount > 2) {
        Log.e(TAG, "onMeasure: More than two child views are not supported.");
    }

    // We'll find the current one below.
    mSlideableView = null;

    // First pass. Measure based on child LayoutParams width/height.
    // Weight will incur a second pass.
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (child.getVisibility() == GONE) {
            lp.dimWhenOffset = false;
            continue;
        }

        if (lp.weight > 0) {
            weightSum += lp.weight;

            // If we have no width, weight is the only contributor to the final size.
            // Measure this view on the weight pass only.
            if (lp.width == 0)
                continue;
        }

        int childWidthSpec;
        final int horizontalMargin = lp.leftMargin + lp.rightMargin;
        if (lp.width == LayoutParams.WRAP_CONTENT) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable - horizontalMargin,
                    MeasureSpec.AT_MOST);
        } else if (lp.width == LayoutParams.MATCH_PARENT) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable - horizontalMargin,
                    MeasureSpec.EXACTLY);
        } else {
            childWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
        }

        int childHeightSpec;
        if (lp.height == LayoutParams.WRAP_CONTENT) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
        } else if (lp.height == LayoutParams.MATCH_PARENT) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
        } else {
            childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
        }

        child.measure(childWidthSpec, childHeightSpec);
        final int childWidth = child.getMeasuredWidth();
        final int childHeight = child.getMeasuredHeight();

        if (heightMode == MeasureSpec.AT_MOST && childHeight > layoutHeight) {
            layoutHeight = Math.min(childHeight, maxLayoutHeight);
        }

        widthRemaining -= childWidth;
        canSlide |= lp.slideable = widthRemaining < 0;
        if (lp.slideable) {
            mSlideableView = child;
        }
    }

    // Resolve weight and make sure non-sliding panels are smaller than the full screen.
    if (canSlide || weightSum > 0) {
        //            final int fixedPanelWidthLimit = widthAvailable - mOverhangSize;

        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);

            if (child.getVisibility() == GONE) {
                continue;
            }

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (child.getVisibility() == GONE) {
                continue;
            }

            final boolean skippedFirstPass = lp.width == 0 && lp.weight > 0;
            final int measuredWidth = skippedFirstPass ? 0 : child.getMeasuredWidth();
            if (canSlide && child != mSlideableView) {
                if (lp.width < 0 && (measuredWidth > widthAvailable || lp.weight > 0)) {
                    // Fixed panels in a sliding configuration should
                    // be clamped to the fixed panel limit.
                    final int childHeightSpec;
                    if (skippedFirstPass) {
                        // Do initial height measurement if we skipped measuring this view
                        // the first time around.
                        if (lp.height == LayoutParams.WRAP_CONTENT) {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
                        } else if (lp.height == LayoutParams.MATCH_PARENT) {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
                        } else {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
                        }
                    } else {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
                                MeasureSpec.EXACTLY);
                    }
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable, MeasureSpec.EXACTLY);
                    child.measure(childWidthSpec, childHeightSpec);
                }
            } else if (lp.weight > 0) {
                int childHeightSpec;
                if (lp.width == 0) {
                    // This was skipped the first time; figure out a real height spec.
                    if (lp.height == LayoutParams.WRAP_CONTENT) {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
                    } else if (lp.height == LayoutParams.MATCH_PARENT) {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
                    } else {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
                    }
                } else {
                    childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
                            MeasureSpec.EXACTLY);
                }

                if (canSlide) {
                    // Consume available space
                    final int horizontalMargin = lp.leftMargin + lp.rightMargin;
                    final int newWidth = widthAvailable - horizontalMargin;
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
                    if (measuredWidth != newWidth) {
                        child.measure(childWidthSpec, childHeightSpec);
                    }
                } else {
                    // Distribute the extra width proportionally similar to LinearLayout
                    final int widthToDistribute = Math.max(0, widthRemaining);
                    final int addedWidth = (int) (lp.weight * widthToDistribute / weightSum);
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(measuredWidth + addedWidth,
                            MeasureSpec.EXACTLY);
                    child.measure(childWidthSpec, childHeightSpec);
                }
            }
        }
    }

    final int measuredWidth = widthSize;
    final int measuredHeight = layoutHeight + getPaddingTop() + getPaddingBottom();

    setMeasuredDimension(measuredWidth, measuredHeight);
    mCanSlide = canSlide;

    if (mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE && !canSlide) {
        // Cancel scrolling in progress, it's no longer relevant.
        mDragHelper.abort();
    }
}

From source file:com.bright.cloudutils.view.ResideLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    if (widthMode != MeasureSpec.EXACTLY) {
        if (isInEditMode()) {
            if (widthMode == MeasureSpec.UNSPECIFIED) {
                widthSize = 300;//from w w w .  j a v  a 2 s .  c o  m
            }
        } else {
            throw new IllegalStateException("Width must have an exact value or MATCH_PARENT");
        }
    } else if (heightMode == MeasureSpec.UNSPECIFIED) {
        if (isInEditMode()) {
            if (heightMode == MeasureSpec.UNSPECIFIED) {
                heightMode = MeasureSpec.AT_MOST;
                heightSize = 300;
            }
        } else {
            throw new IllegalStateException("Height must not be UNSPECIFIED");
        }
    }

    int layoutHeight = 0;
    int maxLayoutHeight = -1;
    switch (heightMode) {
    case MeasureSpec.EXACTLY:
        layoutHeight = maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom();
        break;
    case MeasureSpec.AT_MOST:
        maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom();
        break;
    }

    float weightSum = 0;
    boolean canSlide = false;
    final int widthAvailable = widthSize - getPaddingLeft() - getPaddingRight();
    int widthRemaining = widthAvailable;
    final int childCount = getChildCount();

    if (childCount > 2) {
        Log.e(TAG, "onMeasure: More than two child views are not supported.");
    }

    // We'll find the current one below.
    mSlideableView = null;

    // First pass. Measure based on child LayoutParams width/height.
    // Weight will incur a second pass.
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (child.getVisibility() == GONE) {
            lp.dimWhenOffset = false;
            continue;
        }

        if (lp.weight > 0) {
            weightSum += lp.weight;

            // If we have no width, weight is the only contributor to the
            // final size.
            // Measure this view on the weight pass only.
            if (lp.width == 0)
                continue;
        }

        int childWidthSpec;
        final int horizontalMargin = lp.leftMargin + lp.rightMargin;
        if (lp.width == LayoutParams.WRAP_CONTENT) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable - horizontalMargin,
                    MeasureSpec.AT_MOST);
        } else if (lp.width == LayoutParams.MATCH_PARENT) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable - horizontalMargin,
                    MeasureSpec.EXACTLY);
        } else {
            childWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
        }

        int childHeightSpec;
        if (lp.height == LayoutParams.WRAP_CONTENT) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
        } else if (lp.height == LayoutParams.MATCH_PARENT) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
        } else {
            childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
        }

        child.measure(childWidthSpec, childHeightSpec);
        final int childWidth = child.getMeasuredWidth();
        final int childHeight = child.getMeasuredHeight();

        if (heightMode == MeasureSpec.AT_MOST && childHeight > layoutHeight) {
            layoutHeight = Math.min(childHeight, maxLayoutHeight);
        }

        widthRemaining -= childWidth;
        canSlide |= lp.slideable = widthRemaining < 0;
        if (lp.slideable) {
            mSlideableView = child;
        }
    }

    // Resolve weight and make sure non-sliding panels are smaller than the
    // full screen.
    if (canSlide || weightSum > 0) {
        // final int fixedPanelWidthLimit = widthAvailable - mOverhangSize;

        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);

            if (child.getVisibility() == GONE) {
                continue;
            }

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (child.getVisibility() == GONE) {
                continue;
            }

            final boolean skippedFirstPass = lp.width == 0 && lp.weight > 0;
            final int measuredWidth = skippedFirstPass ? 0 : child.getMeasuredWidth();
            if (canSlide && child != mSlideableView) {
                if (lp.width < 0 && (measuredWidth > widthAvailable || lp.weight > 0)) {
                    // Fixed panels in a sliding configuration should
                    // be clamped to the fixed panel limit.
                    final int childHeightSpec;
                    if (skippedFirstPass) {
                        // Do initial height measurement if we skipped
                        // measuring this view
                        // the first time around.
                        if (lp.height == LayoutParams.WRAP_CONTENT) {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
                        } else if (lp.height == LayoutParams.MATCH_PARENT) {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
                        } else {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
                        }
                    } else {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
                                MeasureSpec.EXACTLY);
                    }
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable, MeasureSpec.EXACTLY);
                    child.measure(childWidthSpec, childHeightSpec);
                }
            } else if (lp.weight > 0) {
                int childHeightSpec;
                if (lp.width == 0) {
                    // This was skipped the first time; figure out a real
                    // height spec.
                    if (lp.height == LayoutParams.WRAP_CONTENT) {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
                    } else if (lp.height == LayoutParams.MATCH_PARENT) {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
                    } else {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
                    }
                } else {
                    childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
                            MeasureSpec.EXACTLY);
                }

                if (canSlide) {
                    // Consume available space
                    final int horizontalMargin = lp.leftMargin + lp.rightMargin;
                    final int newWidth = widthAvailable - horizontalMargin;
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
                    if (measuredWidth != newWidth) {
                        child.measure(childWidthSpec, childHeightSpec);
                    }
                } else {
                    // Distribute the extra width proportionally similar to
                    // LinearLayout
                    final int widthToDistribute = Math.max(0, widthRemaining);
                    final int addedWidth = (int) (lp.weight * widthToDistribute / weightSum);
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(measuredWidth + addedWidth,
                            MeasureSpec.EXACTLY);
                    child.measure(childWidthSpec, childHeightSpec);
                }
            }
        }
    }

    final int measuredWidth = widthSize;
    final int measuredHeight = layoutHeight + getPaddingTop() + getPaddingBottom();

    setMeasuredDimension(measuredWidth, measuredHeight);
    mCanSlide = canSlide;

    if (mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE && !canSlide) {
        // Cancel scrolling in progress, it's no longer relevant.
        mDragHelper.abort();
    }
}

From source file:android.support.design.widget.CoordinatorLayout.java

/**
 * Calculate the desired child rect relative to an anchor rect, respecting both
 * gravity and anchorGravity./*from   ww  w .  j  a  v  a2  s .  c o m*/
 *
 * @param child child view to calculate a rect for
 * @param layoutDirection the desired layout direction for the CoordinatorLayout
 * @param anchorRect rect in CoordinatorLayout coordinates of the anchor view area
 * @param out rect to set to the output values
 */
void getDesiredAnchoredChildRect(View child, int layoutDirection, Rect anchorRect, Rect out) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final int childWidth = child.getMeasuredWidth();
    final int childHeight = child.getMeasuredHeight();
    getDesiredAnchoredChildRectWithoutConstraints(child, layoutDirection, anchorRect, out, lp, childWidth,
            childHeight);
    constrainChildRect(lp, out, childWidth, childHeight);
}

From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final boolean isLayoutRtl = isLayoutRtlSupport();
    if (isLayoutRtl) {
        mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT);
    } else {/*from  w  w w. j av a 2s. c  o  m*/
        mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
    }
    final int width = r - l;
    final int paddingStart = isLayoutRtl ? getPaddingRight() : getPaddingLeft();
    final int paddingEnd = isLayoutRtl ? getPaddingLeft() : getPaddingRight();
    final int paddingTop = getPaddingTop();

    final int childCount = getChildCount();
    int xStart = paddingStart;
    int nextXStart = xStart;

    if (mFirstLayout) {
        mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f;
    }

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int childWidth = child.getMeasuredWidth();
        int offset = 0;

        if (lp.slideable) {
            final int margin = lp.leftMargin + lp.rightMargin;
            final int range = Math.min(nextXStart, width - paddingEnd - mOverhangSize) - xStart - margin;
            mSlideRange = range;
            final int lpMargin = isLayoutRtl ? lp.rightMargin : lp.leftMargin;
            lp.dimWhenOffset = xStart + lpMargin + range + childWidth / 2 > width - paddingEnd;
            final int pos = (int) (range * mSlideOffset);
            xStart += pos + lpMargin;
            mSlideOffset = (float) pos / mSlideRange;
        } else if (mCanSlide && mParallaxBy != 0) {
            offset = (int) ((1 - mSlideOffset) * mParallaxBy);
            xStart = nextXStart;
        } else {
            xStart = nextXStart;
        }

        final int childRight;
        final int childLeft;
        if (isLayoutRtl) {
            childRight = width - xStart + offset;
            childLeft = childRight - childWidth;
        } else {
            childLeft = xStart - offset;
            childRight = childLeft + childWidth;
        }

        final int childTop = paddingTop;
        final int childBottom = childTop + child.getMeasuredHeight();
        child.layout(childLeft, paddingTop, childRight, childBottom);

        nextXStart += child.getWidth();
    }

    if (mFirstLayout) {
        if (mCanSlide) {
            if (mParallaxBy != 0) {
                parallaxOtherViews(mSlideOffset);
            }
            if (((LayoutParams) mSlideableView.getLayoutParams()).dimWhenOffset) {
                dimChildView(mSlideableView, mSlideOffset, mSliderFadeColor);
            }
        } else {
            // Reset the dim level of all children; it's irrelevant when
            // nothing moves.
            for (int i = 0; i < childCount; i++) {
                dimChildView(getChildAt(i), 0, mSliderFadeColor);
            }
        }
        updateObscuredViewsVisibility(mSlideableView);
    }

    mFirstLayout = false;
}

From source file:com.android.dialer.widget.OverlappingPaneLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    if (widthMode != MeasureSpec.EXACTLY) {
        if (isInEditMode()) {
            // Don't crash the layout editor. Consume all of the space if specified
            // or pick a magic number from thin air otherwise.
            // TODO Better communication with tools of this bogus state.
            // It will crash on a real device.
            if (widthMode == MeasureSpec.AT_MOST) {
                widthMode = MeasureSpec.EXACTLY;
            } else if (widthMode == MeasureSpec.UNSPECIFIED) {
                widthMode = MeasureSpec.EXACTLY;
                widthSize = 300;//from  w  ww  .  ja v  a2s . com
            }
        } else {
            throw new IllegalStateException("Width must have an exact value or MATCH_PARENT");
        }
    } else if (heightMode == MeasureSpec.UNSPECIFIED) {
        if (isInEditMode()) {
            // Don't crash the layout editor. Pick a magic number from thin air instead.
            // TODO Better communication with tools of this bogus state.
            // It will crash on a real device.
            if (heightMode == MeasureSpec.UNSPECIFIED) {
                heightMode = MeasureSpec.AT_MOST;
                heightSize = 300;
            }
        } else {
            throw new IllegalStateException("Height must not be UNSPECIFIED");
        }
    }

    int layoutWidth = 0;
    int maxLayoutWidth = -1;
    switch (widthMode) {
    case MeasureSpec.EXACTLY:
        layoutWidth = maxLayoutWidth = widthSize - getPaddingLeft() - getPaddingRight();
        break;
    case MeasureSpec.AT_MOST:
        maxLayoutWidth = widthSize - getPaddingLeft() - getPaddingRight();
        break;
    }

    float weightSum = 0;
    boolean canSlide = false;
    final int heightAvailable = heightSize - getPaddingTop() - getPaddingBottom();
    int heightRemaining = heightAvailable;
    final int childCount = getChildCount();

    if (childCount > 2) {
        Log.e(TAG, "onMeasure: More than two child views are not supported.");
    }

    // We'll find the current one below.
    mSlideableView = null;

    // First pass. Measure based on child LayoutParams width/height.
    // Weight will incur a second pass.
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (child.getVisibility() == GONE) {
            continue;
        }

        if (lp.weight > 0) {
            weightSum += lp.weight;

            // If we have no height, weight is the only contributor to the final size.
            // Measure this view on the weight pass only.
            if (lp.height == 0)
                continue;
        }

        int childHeightSpec;
        final int verticalMargin = lp.topMargin + lp.bottomMargin;
        if (lp.height == LayoutParams.WRAP_CONTENT) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(heightAvailable - verticalMargin,
                    MeasureSpec.AT_MOST);
        } else if (lp.height == LayoutParams.MATCH_PARENT) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(heightAvailable - verticalMargin,
                    MeasureSpec.EXACTLY);
        } else {
            childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
        }

        int childWidthSpec;
        if (lp.width == LayoutParams.WRAP_CONTENT) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(maxLayoutWidth, MeasureSpec.AT_MOST);
        } else if (lp.width == LayoutParams.MATCH_PARENT) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(maxLayoutWidth, MeasureSpec.EXACTLY);
        } else {
            childWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
        }

        child.measure(childWidthSpec, childHeightSpec);
        final int childWidth = child.getMeasuredWidth();
        final int childHeight = child.getMeasuredHeight();

        if (widthMode == MeasureSpec.AT_MOST && childWidth > layoutWidth) {
            layoutWidth = Math.min(childWidth, maxLayoutWidth);
        }

        heightRemaining -= childHeight;
        canSlide |= lp.slideable = heightRemaining < 0;
        if (lp.slideable) {
            mSlideableView = child;
        }
    }

    // Resolve weight and make sure non-sliding panels are smaller than the full screen.
    if (canSlide || weightSum > 0) {
        final int fixedPanelHeightLimit = heightAvailable - mOverhangSize;

        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);

            if (child.getVisibility() == GONE) {
                continue;
            }

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (child.getVisibility() == GONE) {
                continue;
            }

            final boolean skippedFirstPass = lp.height == 0 && lp.weight > 0;
            final int measuredHeight = skippedFirstPass ? 0 : child.getMeasuredHeight();
            if (canSlide && child != mSlideableView) {
                if (lp.height < 0 && (measuredHeight > fixedPanelHeightLimit || lp.weight > 0)) {
                    // Fixed panels in a sliding configuration should
                    // be clamped to the fixed panel limit.
                    final int childWidthSpec;
                    if (skippedFirstPass) {
                        // Do initial width measurement if we skipped measuring this view
                        // the first time around.
                        if (lp.width == LayoutParams.WRAP_CONTENT) {
                            childWidthSpec = MeasureSpec.makeMeasureSpec(maxLayoutWidth, MeasureSpec.AT_MOST);
                        } else if (lp.height == LayoutParams.MATCH_PARENT) {
                            childWidthSpec = MeasureSpec.makeMeasureSpec(maxLayoutWidth, MeasureSpec.EXACTLY);
                        } else {
                            childWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
                        }
                    } else {
                        childWidthSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredWidth(),
                                MeasureSpec.EXACTLY);
                    }
                    final int childHeightSpec = MeasureSpec.makeMeasureSpec(fixedPanelHeightLimit,
                            MeasureSpec.EXACTLY);
                    child.measure(childWidthSpec, childHeightSpec);
                }
            } else if (lp.weight > 0) {
                int childWidthSpec;
                if (lp.height == 0) {
                    // This was skipped the first time; figure out a real width spec.
                    if (lp.width == LayoutParams.WRAP_CONTENT) {
                        childWidthSpec = MeasureSpec.makeMeasureSpec(maxLayoutWidth, MeasureSpec.AT_MOST);
                    } else if (lp.width == LayoutParams.MATCH_PARENT) {
                        childWidthSpec = MeasureSpec.makeMeasureSpec(maxLayoutWidth, MeasureSpec.EXACTLY);
                    } else {
                        childWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
                    }
                } else {
                    childWidthSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredWidth(), MeasureSpec.EXACTLY);
                }

                if (canSlide) {
                    // Consume available space
                    final int verticalMargin = lp.topMargin + lp.bottomMargin;
                    final int newHeight = heightAvailable - verticalMargin;
                    final int childHeightSpec = MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY);
                    if (measuredHeight != newHeight) {
                        child.measure(childWidthSpec, childHeightSpec);
                    }
                } else {
                    // Distribute the extra width proportionally similar to LinearLayout
                    final int heightToDistribute = Math.max(0, heightRemaining);
                    final int addedHeight = (int) (lp.weight * heightToDistribute / weightSum);
                    final int childHeightSpec = MeasureSpec.makeMeasureSpec(measuredHeight + addedHeight,
                            MeasureSpec.EXACTLY);
                    child.measure(childWidthSpec, childHeightSpec);
                }
            }
        }
    }

    final int measuredHeight = heightSize;
    final int measuredWidth = layoutWidth + getPaddingLeft() + getPaddingRight();

    setMeasuredDimension(measuredWidth, measuredHeight);
    mCanSlide = canSlide;

    if (mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE && !canSlide) {
        // Cancel scrolling in progress, it's no longer relevant.
        mDragHelper.abort();
    }
}

From source file:com.example.newviewsplayground.WrappingSlidingPaneLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    final int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    if (widthMode != MeasureSpec.EXACTLY) {
        throw new IllegalStateException("Width must have an exact value or MATCH_PARENT");
    } else if (heightMode == MeasureSpec.UNSPECIFIED) {
        throw new IllegalStateException("Height must not be UNSPECIFIED");
    }//from  w  w w .j  a  v a  2s .c  o m

    int layoutHeight = 0;
    int maxLayoutHeight = -1;
    switch (heightMode) {
    case MeasureSpec.EXACTLY:
        layoutHeight = maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom();
        break;
    case MeasureSpec.AT_MOST:
        maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom();
        break;
    }

    float weightSum = 0;
    boolean canSlide = false;
    int widthRemaining = widthSize - getPaddingLeft() - getPaddingRight();
    final int childCount = getChildCount();

    if (childCount > 2) {
        Log.e(TAG, "onMeasure: More than two child views are not supported.");
    }

    // We'll find the current one below.
    mSlideableView = null;

    // First pass. Measure based on child LayoutParams width/height.
    // Weight will incur a second pass.
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (child.getVisibility() == GONE) {
            lp.dimWhenOffset = false;
            continue;
        }

        if (lp.weight > 0) {
            weightSum += lp.weight;

            // If we have no width, weight is the only contributor to the final size.
            // Measure this view on the weight pass only.
            if (lp.width == 0)
                continue;
        }

        int childWidthSpec;
        final int horizontalMargin = lp.leftMargin + lp.rightMargin;
        if (lp.width == LayoutParams.WRAP_CONTENT) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - horizontalMargin, MeasureSpec.AT_MOST);
        } else if (lp.width == LayoutParams.FILL_PARENT) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - horizontalMargin, MeasureSpec.EXACTLY);
        } else {
            childWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
        }

        int childHeightSpec;
        if (lp.height == LayoutParams.WRAP_CONTENT) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
        } else if (lp.height == LayoutParams.FILL_PARENT) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
        } else {
            childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
        }

        child.measure(childWidthSpec, childHeightSpec);
        final int childWidth = child.getMeasuredWidth();
        final int childHeight = child.getMeasuredHeight();

        if (heightMode == MeasureSpec.AT_MOST && childHeight > layoutHeight) {
            layoutHeight = Math.min(childHeight, maxLayoutHeight);
        }

        widthRemaining -= childWidth;
        canSlide |= lp.slideable = widthRemaining < 0;
        if (lp.slideable) {
            mSlideableView = child;
        }
    }

    // Resolve weight and make sure non-sliding panels are smaller than the full screen.
    if (canSlide || weightSum > 0) {
        final int fixedPanelWidthLimit = widthSize - mOverhangSize;

        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);

            if (child.getVisibility() == GONE) {
                continue;
            }

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            final boolean skippedFirstPass = lp.width == 0 && lp.weight > 0;
            final int measuredWidth = skippedFirstPass ? 0 : child.getMeasuredWidth();
            if (canSlide && child != mSlideableView) {
                if (lp.width < 0 && (measuredWidth > fixedPanelWidthLimit || lp.weight > 0)) {
                    // Fixed panels in a sliding configuration should
                    // be clamped to the fixed panel limit.
                    final int childHeightSpec;
                    if (skippedFirstPass) {
                        // Do initial height measurement if we skipped measuring this view
                        // the first time around.
                        if (lp.height == LayoutParams.WRAP_CONTENT) {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
                        } else if (lp.height == LayoutParams.FILL_PARENT) {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
                        } else {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
                        }
                    } else {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
                                MeasureSpec.EXACTLY);
                    }
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(fixedPanelWidthLimit,
                            MeasureSpec.EXACTLY);
                    child.measure(childWidthSpec, childHeightSpec);
                }
            } else if (lp.weight > 0) {
                int childHeightSpec;
                if (lp.width == 0) {
                    // This was skipped the first time; figure out a real height spec.
                    if (lp.height == LayoutParams.WRAP_CONTENT) {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
                    } else if (lp.height == LayoutParams.FILL_PARENT) {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
                    } else {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
                    }
                } else {
                    childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
                            MeasureSpec.EXACTLY);
                }

                if (canSlide) {
                    // Consume available space
                    final int horizontalMargin = lp.leftMargin + lp.rightMargin;
                    final int newWidth = widthSize - horizontalMargin;
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
                    if (measuredWidth != newWidth) {
                        child.measure(childWidthSpec, childHeightSpec);
                    }
                } else {
                    // Distribute the extra width proportionally similar to LinearLayout
                    final int widthToDistribute = Math.max(0, widthRemaining);
                    final int addedWidth = (int) (lp.weight * widthToDistribute / weightSum);
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(measuredWidth + addedWidth,
                            MeasureSpec.EXACTLY);
                    child.measure(childWidthSpec, childHeightSpec);
                }
            }
        }
    }

    setMeasuredDimension(widthSize, layoutHeight);
    mCanSlide = canSlide;
    if (mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE && !canSlide) {
        // Cancel scrolling in progress, it's no longer relevant.
        mDragHelper.abort();
    }
}

From source file:com.devabit.takestock.ui.widget.FlexboxLayout.java

/**
 * Place a single View when the layout direction is horizontal ({@link #mFlexDirection} is
 * either {@link #FLEX_DIRECTION_ROW} or {@link #FLEX_DIRECTION_ROW_REVERSE}).
 *
 * @param view       the View to be placed
 * @param flexLine   the {@link FlexLine} where the View belongs to
 * @param flexWrap   the flex wrap attribute of this FlexboxLayout
 * @param alignItems the align items attribute of this FlexboxLayout
 * @param left       the left position of the View, which the View's margin is already taken
 *                   into account//from   w w w .j av  a 2s  .c  o  m
 * @param top        the top position of the flex line where the View belongs to. The actual
 *                   View's top position is shifted depending on the flexWrap and alignItems
 *                   attributes
 * @param right      the right position of the View, which the View's margin is already taken
 *                   into account
 * @param bottom     the bottom position of the flex line where the View belongs to. The actual
 *                   View's bottom position is shifted depending on the flexWrap and alignItems
 *                   attributes
 * @see #getAlignItems()
 * @see #setAlignItems(int)
 * @see LayoutParams#alignSelf
 */
private void layoutSingleChildHorizontal(View view, FlexLine flexLine, @FlexWrap int flexWrap, int alignItems,
        int left, int top, int right, int bottom) {
    LayoutParams lp = (LayoutParams) view.getLayoutParams();
    if (lp.alignSelf != LayoutParams.ALIGN_SELF_AUTO) {
        // Expecting the values for alignItems and alignSelf match except for ALIGN_SELF_AUTO.
        // Assigning the alignSelf value as alignItems should work.
        alignItems = lp.alignSelf;
    }
    int crossSize = flexLine.crossSize;
    switch (alignItems) {
    case ALIGN_ITEMS_FLEX_START: // Intentional fall through
    case ALIGN_ITEMS_STRETCH:
        if (flexWrap != FLEX_WRAP_WRAP_REVERSE) {
            view.layout(left, top + lp.topMargin, right, bottom + lp.topMargin);
        } else {
            view.layout(left, top - lp.bottomMargin, right, bottom - lp.bottomMargin);
        }
        break;
    case ALIGN_ITEMS_BASELINE:
        if (flexWrap != FLEX_WRAP_WRAP_REVERSE) {
            int marginTop = flexLine.maxBaseline - view.getBaseline();
            marginTop = Math.max(marginTop, lp.topMargin);
            view.layout(left, top + marginTop, right, bottom + marginTop);
        } else {
            int marginBottom = flexLine.maxBaseline - view.getMeasuredHeight() + view.getBaseline();
            marginBottom = Math.max(marginBottom, lp.bottomMargin);
            view.layout(left, top - marginBottom, right, bottom - marginBottom);
        }
        break;
    case ALIGN_ITEMS_FLEX_END:
        if (flexWrap != FLEX_WRAP_WRAP_REVERSE) {
            view.layout(left, top + crossSize - view.getMeasuredHeight() - lp.bottomMargin, right,
                    top + crossSize - lp.bottomMargin);
        } else {
            // If the flexWrap == FLEX_WRAP_WRAP_REVERSE, the direction of the
            // flexEnd is flipped (from top to bottom).
            view.layout(left, top - crossSize + view.getMeasuredHeight() + lp.topMargin, right,
                    bottom - crossSize + view.getMeasuredHeight() + lp.topMargin);
        }
        break;
    case ALIGN_ITEMS_CENTER:
        int topFromCrossAxis = (crossSize - view.getMeasuredHeight()) / 2;
        if (flexWrap != FLEX_WRAP_WRAP_REVERSE) {
            view.layout(left, top + topFromCrossAxis + lp.topMargin - lp.bottomMargin, right,
                    top + topFromCrossAxis + view.getMeasuredHeight() + lp.topMargin - lp.bottomMargin);
        } else {
            view.layout(left, top - topFromCrossAxis + lp.topMargin - lp.bottomMargin, right,
                    top - topFromCrossAxis + view.getMeasuredHeight() + lp.topMargin - lp.bottomMargin);
        }
        break;
    }
}

From source file:com.chenglong.muscle.ui.LazyViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // For simple implementation, or internal size is always 0.
    // We depend on the container to specify the layout size of
    // our view. We can't really know what it is since we will be
    // adding and removing different arbitrary views and do not
    // want the layout to change as this happens.
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));
    // Children are just made to fill our space.
    int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
    int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
    /*/* www  .  j  a va  2s.c  om*/
    * Make sure all children have been properly measured. Decor views
    * first. Right now we cheat and make this less complicated by assuming
    * decor views won't intersect. We will pin to edges based on gravity.
    */
    int size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp != null && lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                Log.d(TAG, "gravity: " + lp.gravity + " hgrav: " + hgrav + " vgrav: " + vgrav);
                int widthMode = MeasureSpec.AT_MOST;
                int heightMode = MeasureSpec.AT_MOST;
                boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT;
                if (consumeVertical) {
                    widthMode = MeasureSpec.EXACTLY;
                } else if (consumeHorizontal) {
                    heightMode = MeasureSpec.EXACTLY;
                }
                final int widthSpec = MeasureSpec.makeMeasureSpec(childWidthSize, widthMode);
                final int heightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, heightMode);
                child.measure(widthSpec, heightSpec);
                if (consumeVertical) {
                    childHeightSize -= child.getMeasuredHeight();
                } else if (consumeHorizontal) {
                    childWidthSize -= child.getMeasuredWidth();
                }
            }
        }
    }
    mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);
    // Make sure we have created all fragments that we need to have shown.
    mInLayout = true;
    populate();
    mInLayout = false;
    // Page views next.
    size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            if (DEBUG)
                Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp == null || !lp.isDecor) {
                child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec);
            }
        }
    }
}

From source file:cn.emagsoftware.ui.BugFixedSlidingPaneLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    if (widthMode != MeasureSpec.EXACTLY) {
        if (isInEditMode()) {
            // Don't crash the layout editor. Consume all of the space if specified
            // or pick a magic number from thin air otherwise.
            // TODO Better communication with tools of this bogus state.
            // It will crash on a real device.
            if (widthMode == MeasureSpec.AT_MOST) {
                widthMode = MeasureSpec.EXACTLY;
            } else if (widthMode == MeasureSpec.UNSPECIFIED) {
                widthMode = MeasureSpec.EXACTLY;
                widthSize = 300;/*from   ww w.  java2 s .co  m*/
            }
        } else {
            throw new IllegalStateException("Width must have an exact value or MATCH_PARENT");
        }
    } else if (heightMode == MeasureSpec.UNSPECIFIED) {
        if (isInEditMode()) {
            // Don't crash the layout editor. Pick a magic number from thin air instead.
            // TODO Better communication with tools of this bogus state.
            // It will crash on a real device.
            if (heightMode == MeasureSpec.UNSPECIFIED) {
                heightMode = MeasureSpec.AT_MOST;
                heightSize = 300;
            }
        } else {
            throw new IllegalStateException("Height must not be UNSPECIFIED");
        }
    }

    int layoutHeight = 0;
    int maxLayoutHeight = -1;
    switch (heightMode) {
    case MeasureSpec.EXACTLY:
        layoutHeight = maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom();
        break;
    case MeasureSpec.AT_MOST:
        maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom();
        break;
    }

    float weightSum = 0;
    boolean canSlide = false;
    int widthRemaining = widthSize - getPaddingLeft() - getPaddingRight();
    final int childCount = getChildCount();

    if (childCount > 2) {
        Log.e(TAG, "onMeasure: More than two child views are not supported.");
    }

    // We'll find the current one below.
    mSlideableView = null;

    // First pass. Measure based on child LayoutParams width/height.
    // Weight will incur a second pass.
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (child.getVisibility() == GONE) {
            lp.dimWhenOffset = false;
            continue;
        }

        if (lp.weight > 0) {
            weightSum += lp.weight;

            // If we have no width, weight is the only contributor to the final size.
            // Measure this view on the weight pass only.
            if (lp.width == 0)
                continue;
        }

        int childWidthSpec;
        final int horizontalMargin = lp.leftMargin + lp.rightMargin;
        if (lp.width == LayoutParams.WRAP_CONTENT) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - horizontalMargin, MeasureSpec.AT_MOST);
        } else if (lp.width == LayoutParams.FILL_PARENT) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - horizontalMargin, MeasureSpec.EXACTLY);
        } else {
            childWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
        }

        int childHeightSpec;
        if (lp.height == LayoutParams.WRAP_CONTENT) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
        } else if (lp.height == LayoutParams.FILL_PARENT) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
        } else {
            childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
        }

        child.measure(childWidthSpec, childHeightSpec);
        final int childWidth = child.getMeasuredWidth();
        final int childHeight = child.getMeasuredHeight();

        if (heightMode == MeasureSpec.AT_MOST && childHeight > layoutHeight) {
            layoutHeight = Math.min(childHeight, maxLayoutHeight);
        }

        widthRemaining -= childWidth;
        canSlide |= lp.slideable = widthRemaining < 0;
        if (lp.slideable) {
            mSlideableView = child;
        }
    }

    // Resolve weight and make sure non-sliding panels are smaller than the full screen.
    if (canSlide || weightSum > 0) {
        final int fixedPanelWidthLimit = widthSize - mOverhangSize;

        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);

            if (child.getVisibility() == GONE) {
                continue;
            }

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (child.getVisibility() == GONE) {
                continue;
            }

            final boolean skippedFirstPass = lp.width == 0 && lp.weight > 0;
            final int measuredWidth = skippedFirstPass ? 0 : child.getMeasuredWidth();
            if (canSlide && child != mSlideableView) {
                if (lp.width < 0 && (measuredWidth > fixedPanelWidthLimit || lp.weight > 0)) {
                    // Fixed panels in a sliding configuration should
                    // be clamped to the fixed panel limit.
                    final int childHeightSpec;
                    if (skippedFirstPass) {
                        // Do initial height measurement if we skipped measuring this view
                        // the first time around.
                        if (lp.height == LayoutParams.WRAP_CONTENT) {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
                        } else if (lp.height == LayoutParams.FILL_PARENT) {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
                        } else {
                            childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
                        }
                    } else {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
                                MeasureSpec.EXACTLY);
                    }
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(fixedPanelWidthLimit,
                            MeasureSpec.EXACTLY);
                    child.measure(childWidthSpec, childHeightSpec);
                }
            } else if (lp.weight > 0) {
                int childHeightSpec;
                if (lp.width == 0) {
                    // This was skipped the first time; figure out a real height spec.
                    if (lp.height == LayoutParams.WRAP_CONTENT) {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST);
                    } else if (lp.height == LayoutParams.FILL_PARENT) {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY);
                    } else {
                        childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
                    }
                } else {
                    childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
                            MeasureSpec.EXACTLY);
                }

                if (canSlide) {
                    // Consume available space
                    final int horizontalMargin = lp.leftMargin + lp.rightMargin;
                    final int newWidth = widthSize - horizontalMargin;
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
                    if (measuredWidth != newWidth) {
                        child.measure(childWidthSpec, childHeightSpec);
                    }
                } else {
                    // Distribute the extra width proportionally similar to LinearLayout
                    final int widthToDistribute = Math.max(0, widthRemaining);
                    final int addedWidth = (int) (lp.weight * widthToDistribute / weightSum);
                    final int childWidthSpec = MeasureSpec.makeMeasureSpec(measuredWidth + addedWidth,
                            MeasureSpec.EXACTLY);
                    child.measure(childWidthSpec, childHeightSpec);
                }
            }
        }
    }

    setMeasuredDimension(widthSize, layoutHeight);
    mCanSlide = canSlide;
    if (mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE && !canSlide) {
        // Cancel scrolling in progress, it's no longer relevant.
        mDragHelper.abort();
    }
}