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:android.support.design.widget.CoordinatorLayout.java

/**
 * Lay out a child view with respect to a keyline.
 *
 * <p>The keyline represents a horizontal offset from the unpadded starting edge of
 * the CoordinatorLayout. The child's gravity will affect how it is positioned with
 * respect to the keyline.</p>/*from   w  w w. jav  a2s  .  c o  m*/
 *
 * @param child child to lay out
 * @param keyline offset from the starting edge in pixels of the keyline to align with
 * @param layoutDirection ViewCompat constant for layout direction
 */
private void layoutChildWithKeyline(View child, int keyline, int layoutDirection) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final int absGravity = GravityCompat.getAbsoluteGravity(resolveKeylineGravity(lp.gravity), layoutDirection);

    final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int width = getWidth();
    final int height = getHeight();
    final int childWidth = child.getMeasuredWidth();
    final int childHeight = child.getMeasuredHeight();

    if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) {
        keyline = width - keyline;
    }

    int left = getKeyline(keyline) - childWidth;
    int top = 0;

    switch (hgrav) {
    default:
    case Gravity.LEFT:
        // Nothing to do.
        break;
    case Gravity.RIGHT:
        left += childWidth;
        break;
    case Gravity.CENTER_HORIZONTAL:
        left += childWidth / 2;
        break;
    }

    switch (vgrav) {
    default:
    case Gravity.TOP:
        // Do nothing, we're already in position.
        break;
    case Gravity.BOTTOM:
        top += childHeight;
        break;
    case Gravity.CENTER_VERTICAL:
        top += childHeight / 2;
        break;
    }

    // Obey margins and padding
    left = Math.max(getPaddingLeft() + lp.leftMargin,
            Math.min(left, width - getPaddingRight() - childWidth - lp.rightMargin));
    top = Math.max(getPaddingTop() + lp.topMargin,
            Math.min(top, height - getPaddingBottom() - childHeight - lp.bottomMargin));

    child.layout(left, top, left + childWidth, top + childHeight);
}

From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns./*  w  ww. j  av  a2 s.  c  o m*/
 *
 * @param position Position index of the first page currently being displayed.
 *                 Page position+1 will be visible if positionOffset is nonzero.
 * @param offset Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        // BrantApps Change: Renamed scrollx to scrolly, paddingLeft to paddingTop, paddingRight to paddingBottom & width to height
        // BrantApps Change: Also changed method calls to get the four values
        final int scrollY = getScrollY();
        int paddingTop = getPaddingTop();
        int paddingBottom = getPaddingBottom();
        final int height = getHeight();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
            // BrantApps Change: Renamed childLeft to childTop
            int childTop = 0;
            // BrantApps Change: In switch statement changed 3 calls to getMeasuredWidth() to getMeasuredHeight()
            switch (hgrav) {
            default:
                childTop = paddingTop;
                break;
            case Gravity.LEFT:
                childTop = paddingTop;
                // BrantApps Change: Was paddingLeft += child.getWidth();
                paddingTop += child.getHeight();
                break;
            case Gravity.CENTER_HORIZONTAL:
                childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                break;
            case Gravity.RIGHT:
                childTop = height - paddingBottom - child.getMeasuredHeight();
                paddingBottom += child.getMeasuredHeight();
                break;
            }
            childTop += scrollY;

            // BrantApps Change: Was final int childOffset = childLeft - child.getLeft();
            final int childOffset = childTop - child.getTop();
            if (childOffset != 0) {
                child.offsetTopAndBottom(childOffset);
            }
        }
    }

    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    mCalledSuper = true;
}

From source file:com.common.view.slidingfinish.CustomSlidingPaneLayout.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  w  w  .j ava  2s.c om
            }
        } 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;
    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.FILL_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.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 = 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 > 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 = 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.bloomimpact.bancus.ui.views.VerticalViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns.// ww w  .j  a v  a2 s . c om
 *
 * @param position Position index of the first page currently being displayed.
 *                 Page position+1 will be visible if positionOffset is nonzero.
 * @param offset Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        final int scrollY = getScrollY();
        int paddingTop = getPaddingTop();
        int paddingBottom = getPaddingBottom();
        final int height = getHeight();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
            int childTop = 0;
            switch (hgrav) {
            default:
                childTop = paddingTop;
                break;
            case Gravity.TOP:
                childTop = paddingTop;
                paddingTop += child.getHeight();
                break;
            case Gravity.CENTER_VERTICAL:
                childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                break;
            case Gravity.BOTTOM:
                childTop = height - paddingTop - child.getMeasuredHeight();
                paddingBottom += child.getMeasuredHeight();
                break;
            }
            childTop += scrollY;

            final int childOffset = childTop - child.getTop();
            if (childOffset != 0) {
                child.offsetTopAndBottom(childOffset);
            }
        }
    }

    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }

    if (mPageTransformer != null) {
        final int scrollY = getScrollY();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;

            final float transformPos = (float) (child.getTop() - scrollY) / getClientHeight();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

From source file:com.appunite.list.HorizontalListView.java

/**
 * Layout a child that has been measured, preserving its top position.
 * TODO: unify with setUpChild.//ww w .j  a  v a2  s  .com
 * @param child The child.
 */
private void relayoutMeasuredItem(View child) {
    final int w = child.getMeasuredWidth();
    final int h = child.getMeasuredHeight();
    final int childLeft = child.getLeft();
    final int childRight = childLeft + w;
    final int childTop = mListPadding.top;
    final int childBottom = childTop + h;
    child.layout(childLeft, childTop, childRight, childBottom);
}

From source file:com.appunite.list.ListView.java

/**
 * Layout a child that has been measured, preserving its top position.
 * TODO: unify with setUpChild./* w w w.j ava  2s.co  m*/
 * @param child The child.
 */
private void relayoutMeasuredItem(View child) {
    final int w = child.getMeasuredWidth();
    final int h = child.getMeasuredHeight();
    final int childLeft = mListPadding.left;
    final int childRight = childLeft + w;
    final int childTop = child.getTop();
    final int childBottom = childTop + h;
    child.layout(childLeft, childTop, childRight, childBottom);
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

/**
 * Layout a child that has been measured, preserving its top position. TODO: unify with setUpChild.
 * /*ww w  . ja  va  2s. com*/
 * @param child
 *           The child.
 */
private void relayoutMeasuredItem(View child) {
    final int w = child.getMeasuredWidth();
    final int h = child.getMeasuredHeight();

    final int childTop = mListPadding.top;
    final int childBottom = childTop + h;

    final int childLeft = child.getLeft();
    final int childRight = childLeft + w;

    child.layout(childLeft, childTop, childRight, childBottom);
}

From source file:beichen.douban.ui.view.LazyViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;//w w w . java  2s  . c o m
    populate();
    mInLayout = false;

    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    final int scrollX = getScrollX();

    int decorCount = 0;

    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            int childLeft = 0;
            int childTop = 0;
            if (lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                }
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                }
                childLeft += scrollX;
                decorCount++;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            } else if ((ii = infoForChild(child)) != null) {
                int loff = (width + mPageMargin) * ii.position;
                childLeft = paddingLeft + loff;
                childTop = paddingTop;
                if (DEBUG)
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            }
        }
    }
    mTopPageBounds = paddingTop;
    mBottomPageBounds = height - paddingBottom;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

public int[] measureChild(View child) {
    measureItem(child);/*from ww  w  .j ava 2  s .  c  o m*/

    int w = child.getMeasuredWidth();
    int h = child.getMeasuredHeight();

    return new int[] { w, h };
}

From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.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;/*  w  w  w.  j  a v  a 2  s  .  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 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.FILL_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.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 = 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 > 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 = 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();
    }
}