Example usage for android.view ViewGroup getChildMeasureSpec

List of usage examples for android.view ViewGroup getChildMeasureSpec

Introduction

In this page you can find the example usage for android.view ViewGroup getChildMeasureSpec.

Prototype

public static int getChildMeasureSpec(int spec, int padding, int childDimension) 

Source Link

Document

Does the hard part of measureChildren: figuring out the MeasureSpec to pass to a particular child.

Usage

From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java

private void setUpChild(View child, int offset, int x, boolean fromLeft) {

    // Respect layout params that are already in the view. Otherwise
    // make some up...
    LayoutParams lp = child.getLayoutParams();
    if (lp == null) {
        lp = (LayoutParams) generateDefaultLayoutParams();
    }/*from www.ja  va2s  . com*/

    addViewInLayout(child, fromLeft ? -1 : 0, lp);

    if (mAllowChildSelection) {
        // final boolean wantfocus = offset == 0;
        // child.setSelected( wantfocus );
        // if( wantfocus ){
        // child.requestFocus();
        // }
    }

    // Get measure specs
    int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec, mPaddingTop + mPaddingBottom,
            lp.height);
    int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec, mPaddingLeft + mPaddingRight,
            lp.width);

    // Measure child
    child.measure(childWidthSpec, childHeightSpec);

    int childLeft;
    int childRight;

    // Position vertically based on gravity setting
    int childTop = calculateTop(child, true);
    int childBottom = childTop + child.getMeasuredHeight();

    int width = child.getMeasuredWidth();
    if (fromLeft) {
        childLeft = x;
        childRight = childLeft + width;
    } else {
        childLeft = x - width;
        childRight = x;
    }

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

}

From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java

private void layoutChildren() {

    int total = getTotalPages();
    int x = mPaddingLeft;

    for (int i = 0; i < total; i++) {
        View child = getScreenAt(i);

        if (null == child)
            continue;

        LayoutParams lp = child.getLayoutParams();

        // Get measure specs
        int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec, mPaddingTop + mPaddingBottom,
                lp.height);//w  w w.ja v  a 2 s.c o  m
        int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec, mPaddingLeft + mPaddingRight,
                lp.width);

        // Measure child
        child.measure(childWidthSpec, childHeightSpec);

        int childLeft;
        int childRight;

        // Position vertically based on gravity setting
        int childTop = calculateTop(child, true);
        int childBottom = childTop + child.getMeasuredHeight();

        int width = child.getMeasuredWidth();
        childLeft = x;
        childRight = childLeft + width;

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

From source file:com.android.mail.browse.ConversationContainer.java

/**
 * Copied/stolen from {@link ListView}./* w  ww.  j  a v a  2  s. c  o m*/
 */
private void measureOverlayView(View child) {
    MarginLayoutParams p = (MarginLayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (MarginLayoutParams) generateDefaultLayoutParams();
    }

    int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec,
            getPaddingLeft() + getPaddingRight() + p.leftMargin + p.rightMargin, p.width);
    int lpHeight = p.height;
    int childHeightSpec;
    if (lpHeight > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    child.measure(childWidthSpec, childHeightSpec);
}

From source file:android.widget.Gallery.java

/**
 * Helper for makeAndAddView to set the position of a view and fill out its
 * layout parameters.//from w  w w .  j a  v a2 s. c om
 * 
 * @param child The view to position
 * @param offset Offset from the selected position
 * @param x X-coordinate indicating where this view should be placed. This
 *        will either be the left or right edge of the view, depending on
 *        the fromLeft parameter
 * @param fromLeft Are we positioning views based on the left edge? (i.e.,
 *        building from left to right)?
 */
private void setUpChild(View child, int offset, int x, boolean fromLeft) {

    // Respect layout params that are already in the view. Otherwise
    // make some up...
    Gallery.LayoutParams lp = (Gallery.LayoutParams) child.getLayoutParams();
    if (lp == null) {
        lp = (Gallery.LayoutParams) generateDefaultLayoutParams();
    }

    addViewInLayout(child, fromLeft != mIsRtl ? -1 : 0, lp);

    child.setSelected(offset == 0);

    // Get measure specs
    int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec,
            mSpinnerPadding.top + mSpinnerPadding.bottom, lp.height);
    int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec,
            mSpinnerPadding.left + mSpinnerPadding.right, lp.width);

    // Measure child
    child.measure(childWidthSpec, childHeightSpec);

    int childLeft;
    int childRight;

    // Position vertically based on gravity setting
    int childTop = calculateTop(child, true);
    int childBottom = childTop + child.getMeasuredHeight();

    int width = child.getMeasuredWidth();
    if (fromLeft) {
        childLeft = x;
        childRight = childLeft + width;
    } else {
        childLeft = x - width;
        childRight = x;
    }

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

From source file:org.androfarsh.widget.DragGridLayout.java

@Override
protected void measureChild(View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec) {
    final int childWidthMeasureSpec;
    final int childHeightMeasureSpec;
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();

    if (mRootView == child) {
        childWidthMeasureSpec = parentWidthMeasureSpec;
        childHeightMeasureSpec = parentHeightMeasureSpec;
    } else if (((mDragNode) != null) && (mDragNode.view == child)) {
        final int width = mDragNode.currentRect.width();
        final int height = mDragNode.currentRect.height();

        final int widthSize = MeasureSpec.getSize(parentWidthMeasureSpec);
        final int heightSize = MeasureSpec.getSize(parentHeightMeasureSpec);

        childWidthMeasureSpec = ViewGroup.getChildMeasureSpec(
                MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY),
                getPaddingLeft() + getPaddingRight(), width);
        childHeightMeasureSpec = ViewGroup.getChildMeasureSpec(
                MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY),
                getPaddingTop() + getPaddingBottom(), height);
    } else {//from   w ww.ja v a2s.co  m
        final int width = (lp.mHorizontalSize * mCellSize) - (lp.leftMargin + lp.rightMargin);
        final int height = (lp.mVerticalSize * mCellSize) - (lp.topMargin + lp.bottomMargin);

        childWidthMeasureSpec = ViewGroup.getChildMeasureSpec(parentWidthMeasureSpec,
                getPaddingLeft() + getPaddingRight(), width);
        childHeightMeasureSpec = ViewGroup.getChildMeasureSpec(parentHeightMeasureSpec,
                getPaddingTop() + getPaddingBottom(), height);
    }
    child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
}

From source file:com.huewu.pla.lib.internal.PLA_ListView.java

private void measureScrapChild(View child, int position, int widthMeasureSpec) {
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
        child.setLayoutParams(p);//from w w  w  .j a  v  a  2  s . c  o  m
    }
    p.viewType = mAdapter.getItemViewType(position);
    p.forceAdd = true;

    int childWidthSpec = ViewGroup.getChildMeasureSpec(widthMeasureSpec, mListPadding.left + mListPadding.right,
            p.width);
    int lpHeight = p.height;
    int childHeightSpec;
    if (lpHeight > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    child.measure(childWidthSpec, childHeightSpec);
}

From source file:io.github.clendy.leanback.widget.GridLayoutManager.java

private void measureScrapChild(int position, int widthSpec, int heightSpec, int[] measuredDimension) {
    View view = mRecycler.getViewForPosition(position);
    if (view != null) {
        LayoutParams p = (LayoutParams) view.getLayoutParams();
        int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec, getPaddingLeft() + getPaddingRight(),
                p.width);//  w  w  w  .  ja v a 2  s  .  c om
        int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec, getPaddingTop() + getPaddingBottom(),
                p.height);
        view.measure(childWidthSpec, childHeightSpec);
        measuredDimension[0] = view.getMeasuredWidth();
        measuredDimension[1] = view.getMeasuredHeight();
        mRecycler.recycleView(view);
    }
}

From source file:android.support.v17.leanback.widget.GridLayoutManager.java

private void measureScrapChild(int position, int widthSpec, int heightSpec, int[] measuredDimension) {
    View view = mRecycler.getViewForPosition(position);
    if (view != null) {
        final LayoutParams p = (LayoutParams) view.getLayoutParams();
        calculateItemDecorationsForChild(view, sTempRect);
        int widthUsed = p.leftMargin + p.rightMargin + sTempRect.left + sTempRect.right;
        int heightUsed = p.topMargin + p.bottomMargin + sTempRect.top + sTempRect.bottom;

        int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
                getPaddingLeft() + getPaddingRight() + widthUsed, p.width);
        int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
                getPaddingTop() + getPaddingBottom() + heightUsed, p.height);
        view.measure(childWidthSpec, childHeightSpec);

        measuredDimension[0] = getDecoratedMeasuredWidthWithMargin(view);
        measuredDimension[1] = getDecoratedMeasuredHeightWithMargin(view);
        mRecycler.recycleView(view);//  www.j  a  v a  2 s  . c  o m
    }
}

From source file:net.simonvt.staggeredgridview.StaggeredGridView.java

private View makeAndAddView(int position) {
    View child = obtainView(position, isScrap);
    LayoutParams lp = (LayoutParams) child.getLayoutParams();

    final boolean recycled = isScrap[0];
    final int addAt = position < firstPosition ? 0 : -1;
    if (recycled) {
        attachViewToParent(child, addAt, child.getLayoutParams());
    } else {/*  w  w w.  java2  s. c  om*/
        addViewInLayout(child, addAt, child.getLayoutParams());
    }

    int childHeightSpec = ViewGroup.getChildMeasureSpec(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            0, lp.height);

    int childWidthSpec = ViewGroup
            .getChildMeasureSpec(MeasureSpec.makeMeasureSpec(colWidth, MeasureSpec.EXACTLY), 0, lp.width);
    child.measure(childWidthSpec, childHeightSpec);

    return child;
}

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

private void measureScrapChild(View child, int position, int heightMeasureSpec) {
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (LayoutParams) generateDefaultLayoutParams();
        child.setLayoutParams(p);/*  ww w.  j ava 2 s .com*/
    }
    p.viewType = mAdapter.getItemViewType(position);
    p.forceAdd = true;

    int childHeightSpec = ViewGroup.getChildMeasureSpec(heightMeasureSpec,
            mListPadding.top + mListPadding.bottom, p.height);
    int lpWidth = p.width;
    int childWidthSpec;
    if (lpWidth > 0) {
        childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, MeasureSpec.EXACTLY);
    } else {
        childWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    child.measure(childWidthSpec, childHeightSpec);
}