Example usage for android.view View measure

List of usage examples for android.view View measure

Introduction

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

Prototype

public final void measure(int widthMeasureSpec, int heightMeasureSpec) 

Source Link

Document

This is called to find out how big a view should be.

Usage

From source file:com.icloud.listenbook.base.view.DraggableGridViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int childCount = getChildCount();
    mPageCount = (childCount + mPageSize - 1) / mPageSize;
    mGridWidth = (getWidth() - mPaddingLeft - mPaddingRight - (mColCount - 1) * mGridGap) / mColCount;
    mGridHeight = (getHeight() - mPaddingTop - mPaddingButtom - (mRowCount - 1) * mGridGap) / mRowCount;

    mMaxOverScrollSize = mGridWidth / 2;
    mEdgeSize = mGridWidth / 2;//from w w w  .  j a  v a  2 s.  c  o  m
    newPositions.clear();
    // ? 
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final Rect rect = getRectByPosition(i);
        child.measure(MeasureSpec.makeMeasureSpec(rect.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(rect.height(), MeasureSpec.EXACTLY));
        DEBUG_LOG("child.layout position=" + i + ", rect=" + rect);
        child.layout(rect.left, rect.top, rect.right, rect.bottom);
        newPositions.add(-1);
    }
    // ??
    if (mCurItem > 0 && mCurItem < mPageCount) {
        final int curItem = mCurItem;
        mCurItem = 0;
        setCurrentItem(curItem);
    }
}

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

/**
 * Copied/stolen from {@link ListView}.//from ww  w.  ja  v a2 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:com.icloud.listenbook.base.view.DraggableGridViewPager.java

/***
 * ?//w  ww.jav  a2  s .  c  om
 * **/
private void animateDragged() {
    if (mLastDragged >= 0) {
        final View v = getChildAt(mLastDragged);

        final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        r.inset(-r.width() / 20, -r.height() / 20);
        v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
        v.layout(r.left, r.top, r.right, r.bottom);

        AnimationSet animSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
        scale.setDuration(ANIMATION_DURATION);
        AlphaAnimation alpha = new AlphaAnimation(1, .5f);
        alpha.setDuration(ANIMATION_DURATION);

        animSet.addAnimation(scale);
        animSet.addAnimation(alpha);
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);

        v.clearAnimation();
        v.startAnimation(animSet);
    }
}

From source file:android.support.v7.widget.WrapLinearLayoutManager.java

private void measureChild(RecyclerView.Recycler recycler, int position, int widthSize, int heightSize,
        int[] dimensions) {
    final View child;
    try {//from  w  w w.  ja  v a  2  s .com
        child = recycler.getViewForPosition(position);
    } catch (IndexOutOfBoundsException e) {
        if (BuildConfig.DEBUG) {
            Log.w("LinearLayoutManager",
                    "LinearLayoutManager doesn't work well with animations. Consider switching them off", e);
        }
        return;
    }

    final RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) child.getLayoutParams();

    final int hPadding = getPaddingLeft() + getPaddingRight();
    final int vPadding = getPaddingTop() + getPaddingBottom();

    final int hMargin = p.leftMargin + p.rightMargin;
    final int vMargin = p.topMargin + p.bottomMargin;

    // we must make insets dirty in order calculateItemDecorationsForChild to work
    makeInsetsDirty(p);
    // this method should be called before any getXxxDecorationXxx() methods
    calculateItemDecorationsForChild(child, tmpRect);

    final int hDecoration = getRightDecorationWidth(child) + getLeftDecorationWidth(child);
    final int vDecoration = getTopDecorationHeight(child) + getBottomDecorationHeight(child);

    final int childWidthSpec = getChildMeasureSpec(widthSize, hPadding + hMargin + hDecoration, p.width,
            canScrollHorizontally());
    final int childHeightSpec = getChildMeasureSpec(heightSize, vPadding + vMargin + vDecoration, p.height,
            canScrollVertically());

    child.measure(childWidthSpec, childHeightSpec);

    dimensions[CHILD_WIDTH] = getDecoratedMeasuredWidth(child) + p.leftMargin + p.rightMargin;
    dimensions[CHILD_HEIGHT] = getDecoratedMeasuredHeight(child) + p.bottomMargin + p.topMargin;

    // as view is recycled let's not keep old measured values
    makeInsetsDirty(p);
    recycler.recycleView(child);
}

From source file:beautician.beauty.android.views.HorizontalListView.java

/**
 * Measure the provided child./*from  w  w w  .j a  v a 2s .c  o m*/
 *
 * @param child The child.
 */
private void measureChild(View child) {
    LayoutParams childLayoutParams = getLayoutParams(child);
    int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec,
            getPaddingTop() + getPaddingBottom(), childLayoutParams.height);

    int childWidthSpec;
    if (childLayoutParams.width > 0) {
        childWidthSpec = MeasureSpec.makeMeasureSpec(childLayoutParams.width, MeasureSpec.EXACTLY);
    } else {
        childWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }

    child.measure(childWidthSpec, childHeightSpec);
}

From source file:bw.com.yunifangstore.view.LazyViewPager.java

@Override
public void addView(View child, int index, LayoutParams params) {
    if (mInLayout) {
        addViewInLayout(child, index, params);
        child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec);
    } else {/*ww  w . j  av a  2  s.  c o  m*/
        super.addView(child, index, params);
    }

    if (USE_CACHE) {
        if (child.getVisibility() != GONE) {
            child.setDrawingCacheEnabled(mScrollingCacheEnabled);
        } else {
            child.setDrawingCacheEnabled(false);
        }
    }
}

From source file:com.example.stickablelistview.StickListView.java

/**
 * Measure the provided child.//ww  w.  j a  va2  s  .  c  om
 *
 * @param child The child.
 */
private void measureChild(View child) {
    ViewGroup.LayoutParams childLayoutParams = getLayoutParams(child);
    int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec, getPaddingLeft() + getPaddingRight(),
            childLayoutParams.width);

    int childHeightSpec;
    if (childLayoutParams.height > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(childLayoutParams.height, MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }

    child.measure(childWidthSpec, childHeightSpec);
}

From source file:aksha.upcomingdemo.HorizontalListView.java

/**
 * Measure the provided child./*from  w  w w .  ja  va 2s  .co m*/
 *
 * @param child The child.
 */
private void measureChild(View child) {
    ViewGroup.LayoutParams childLayoutParams = getLayoutParams(child);
    int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec,
            getPaddingTop() + getPaddingBottom(), childLayoutParams.height);

    int childWidthSpec;
    if (childLayoutParams.width > 0) {
        childWidthSpec = MeasureSpec.makeMeasureSpec(childLayoutParams.width, MeasureSpec.EXACTLY);
    } else {
        childWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }

    child.measure(childWidthSpec, childHeightSpec);
}

From source file:com.actionbarsherlock.internal.widget.IcsSpinner.java

int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
    if (adapter == null) {
        return 0;
    }//from  w  w  w. j ava  2s .  c o  m

    int width = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    // Make sure the number of items we'll measure is capped. If it's a huge data set
    // with wildly varying sizes, oh well.
    int start = Math.max(0, getSelectedItemPosition());
    final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
    final int count = end - start;
    start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
    for (int i = start; i < end; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        itemView = adapter.getView(i, itemView, this);
        if (itemView.getLayoutParams() == null) {
            itemView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        width = Math.max(width, itemView.getMeasuredWidth());
    }

    // Add background padding to measured width
    if (background != null) {
        background.getPadding(mTempRect);
        width += mTempRect.left + mTempRect.right;
    }

    return width;
}

From source file:android.car.ui.provider.CarDrawerLayout.java

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

    if (widthMode != MeasureSpec.EXACTLY || heightMode != 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.UNSPECIFIED) {
                widthSize = 300;//from  w w w . j av  a2 s . co  m
            } else if (heightMode == MeasureSpec.UNSPECIFIED) {
                heightSize = 300;
            }
        } else {
            throw new IllegalArgumentException("DrawerLayout must be measured with MeasureSpec.EXACTLY.");
        }
    }

    setMeasuredDimension(widthSize, heightSize);

    View view = findContentView();
    LayoutParams lp = ((LayoutParams) view.getLayoutParams());
    // Content views get measured at exactly the layout's size.
    final int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - lp.leftMargin - lp.rightMargin,
            MeasureSpec.EXACTLY);
    final int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize - lp.topMargin - lp.bottomMargin,
            MeasureSpec.EXACTLY);
    view.measure(contentWidthSpec, contentHeightSpec);

    view = findDrawerView();
    lp = ((LayoutParams) view.getLayoutParams());
    final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, lp.leftMargin + lp.rightMargin, lp.width);
    final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec, lp.topMargin + lp.bottomMargin,
            lp.height);
    view.measure(drawerWidthSpec, drawerHeightSpec);
}