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:cn.lanmei.com.dingdong_2.ItemDecoration.StickyHeaderDecoration.java

private RecyclerView.ViewHolder getHeader(RecyclerView parent, int position) {

    final long key = mAdapter.getHeaderId(position);

    if (mHeaderCache.containsKey(key)) {
        return mHeaderCache.get(key);
    } else {// w ww . j  av a2s .  c  o m

        final RecyclerView.ViewHolder holder = mAdapter.onCreateHeaderViewHolder(parent);
        final View header = holder.itemView;

        //noinspection unchecked
        mAdapter.onBindHeaderViewHolder(holder, position);

        int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED);

        int childWidth = ViewGroup.getChildMeasureSpec(widthSpec,
                parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width);
        int childHeight = ViewGroup.getChildMeasureSpec(heightSpec,
                parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height);

        header.measure(childWidth, childHeight);
        header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());

        mHeaderCache.put(key, holder);

        return holder;
    }

}

From source file:android.support.v7.internal.widget.ActionBarOverlayLayout.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final int count = getChildCount();

    final int parentLeft = getPaddingLeft();
    final int parentRight = right - left - getPaddingRight();

    final int parentTop = getPaddingTop();
    final int parentBottom = bottom - top - getPaddingBottom();

    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            final int width = child.getMeasuredWidth();
            final int height = child.getMeasuredHeight();

            int childLeft = parentLeft + lp.leftMargin;
            int childTop;
            if (child == mActionBarBottom) {
                childTop = parentBottom - height - lp.bottomMargin;
            } else {
                childTop = parentTop + lp.topMargin;
            }//ww  w  .j ava  2 s.com

            child.layout(childLeft, childTop, childLeft + width, childTop + height);
        }
    }
}

From source file:ca.barrenechea.widget.recyclerview.decoration.StickyHeaderDecoration.java

private RecyclerView.ViewHolder getHeader(RecyclerView parent, int position) {
    final long key = mAdapter.getHeaderId(position);

    if (mHeaderCache.containsKey(key)) {
        return mHeaderCache.get(key);
    } else {/*from ww  w .  j a  v a 2  s.  com*/
        final RecyclerView.ViewHolder holder = mAdapter.onCreateHeaderViewHolder(parent);
        final View header = holder.itemView;

        //noinspection unchecked
        mAdapter.onBindHeaderViewHolder(holder, position);

        int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getMeasuredWidth(), View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getMeasuredHeight(),
                View.MeasureSpec.UNSPECIFIED);

        int childWidth = ViewGroup.getChildMeasureSpec(widthSpec,
                parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width);
        int childHeight = ViewGroup.getChildMeasureSpec(heightSpec,
                parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height);

        header.measure(childWidth, childHeight);
        header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());

        mHeaderCache.put(key, holder);

        return holder;
    }
}

From source file:com.acbelter.scheduleview.ScheduleView.java

private void positionItemViews() {
    if (mAdapter == null) {
        return;// www.  j  a va  2 s .  co m
    }

    View child;
    final int right = mViewWidth - getPaddingRight() - mItemPaddingRight;
    for (int i = 0; i < mAdapter.getCount(); i++) {
        child = getChildAt(i);
        int width = child.getMeasuredWidth();
        int height = child.getMeasuredHeight();

        GeneralScheduleItem item = mAdapter.getItem(i);

        int top = mListY + mInternalPaddingTop + getPaddingTop() + mTimeMarkHeight / 2
                + calculateDistance(mStartTime, getTimeInMillis(item.getStartTime()));

        child.layout(right - width, top, right, top + height);
    }
}

From source file:com.actionbarsherlock.internal.view.menu.ActionMenuView.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (!mFormatItems) {
        super.onLayout(changed, left, top, right, bottom);
        return;/*from  w  w w.j  a  v  a 2s  . c  om*/
    }

    final int childCount = getChildCount();
    final int midVertical = (top + bottom) / 2;
    final int dividerWidth = 0;//getDividerWidth();
    int overflowWidth = 0;
    //UNUSED int nonOverflowWidth = 0;
    int nonOverflowCount = 0;
    int widthRemaining = right - left - getPaddingRight() - getPaddingLeft();
    boolean hasOverflow = false;
    for (int i = 0; i < childCount; i++) {
        final View v = getChildAt(i);
        if (v.getVisibility() == GONE) {
            continue;
        }

        LayoutParams p = (LayoutParams) v.getLayoutParams();
        if (p.isOverflowButton) {
            overflowWidth = v.getMeasuredWidth();
            if (hasDividerBeforeChildAt(i)) {
                overflowWidth += dividerWidth;
            }

            int height = v.getMeasuredHeight();
            int r = getWidth() - getPaddingRight() - p.rightMargin;
            int l = r - overflowWidth;
            int t = midVertical - (height / 2);
            int b = t + height;
            v.layout(l, t, r, b);

            widthRemaining -= overflowWidth;
            hasOverflow = true;
        } else {
            final int size = v.getMeasuredWidth() + p.leftMargin + p.rightMargin;
            //UNUSED nonOverflowWidth += size;
            widthRemaining -= size;
            //if (hasDividerBeforeChildAt(i)) {
            //UNUSED nonOverflowWidth += dividerWidth;
            //}
            nonOverflowCount++;
        }
    }

    if (childCount == 1 && !hasOverflow) {
        // Center a single child
        final View v = getChildAt(0);
        final int width = v.getMeasuredWidth();
        final int height = v.getMeasuredHeight();
        final int midHorizontal = (right - left) / 2;
        final int l = midHorizontal - width / 2;
        final int t = midVertical - height / 2;
        v.layout(l, t, l + width, t + height);
        return;
    }

    final int spacerCount = nonOverflowCount - (hasOverflow ? 0 : 1);
    final int spacerSize = Math.max(0, spacerCount > 0 ? widthRemaining / spacerCount : 0);

    int startLeft = getPaddingLeft();
    for (int i = 0; i < childCount; i++) {
        final View v = getChildAt(i);
        final LayoutParams lp = (LayoutParams) v.getLayoutParams();
        if (v.getVisibility() == GONE || lp.isOverflowButton) {
            continue;
        }

        startLeft += lp.leftMargin;
        int width = v.getMeasuredWidth();
        int height = v.getMeasuredHeight();
        int t = midVertical - height / 2;
        v.layout(startLeft, t, startLeft + width, t + height);
        startLeft += width + lp.rightMargin + spacerSize;
    }
}

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

/**
 * Executes a measure pass over the specified child overlay view and returns the measured
 * height. The measurement uses whatever the current container's width measure spec is.
 * This method ignores view visibility and returns the height that the view would be if visible.
 *
 * @param overlayView an overlay view to measure. does not actually have to be attached yet.
 * @return height that the view would be if it was visible
 */// w  w  w  .j av a2  s  . c  om
public int measureOverlay(View overlayView) {
    measureOverlayView(overlayView);
    return overlayView.getMeasuredHeight();
}

From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java

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

    // Single-use layout; just ignore the mode and use available space.
    // Clamp to maxWidth.
    if (mMaxWidth >= 0) {
        widthSize = Math.min(widthSize, mMaxWidth);
    }/*from w w w  . j  a  v  a  2 s .  c o  m*/

    final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
    final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
    final int widthPadding = getPaddingLeft() + getPaddingRight();
    int heightUsed = getPaddingTop() + getPaddingBottom();

    // Measure always-show children first.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (lp.alwaysShow && child.getVisibility() != GONE) {
            measureChildWithMargins(child, widthSpec, widthPadding, heightSpec, heightUsed);
            heightUsed += lp.topMargin + child.getMeasuredHeight() + lp.bottomMargin;
        }
    }

    final int alwaysShowHeight = heightUsed;

    // And now the rest.
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (!lp.alwaysShow && child.getVisibility() != GONE) {
            measureChildWithMargins(child, widthSpec, widthPadding, heightSpec, heightUsed);
            heightUsed += lp.topMargin + child.getMeasuredHeight() + lp.bottomMargin;
        }
    }

    mCollapsibleHeight = Math.max(0, heightUsed - alwaysShowHeight - getMaxCollapsedHeight());

    if (mIsLaidOut) {
        mCollapseOffset = Math.min(mCollapseOffset, mCollapsibleHeight);
    } else {
        // Start out collapsed at first unless we restored state for otherwise
        mCollapseOffset = mOpenOnLayout ? 0 : mCollapsibleHeight;
    }

    mTopOffset = Math.max(0, heightSize - heightUsed) + (int) mCollapseOffset;

    setMeasuredDimension(sourceWidth, heightSize);
}

From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int width = getWidth();

    int ypos = mTopOffset;
    int leftEdge = getPaddingLeft();
    int rightEdge = width - getPaddingRight();

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (child.getVisibility() == GONE) {
            continue;
        }//from w  ww  .ja  va 2s. com

        int top = ypos + lp.topMargin;
        if (lp.ignoreOffset) {
            top -= mCollapseOffset;
        }
        final int bottom = top + child.getMeasuredHeight();

        final int childWidth = child.getMeasuredWidth();
        final int widthAvailable = rightEdge - leftEdge;
        final int left = leftEdge + (widthAvailable - childWidth) / 2;
        final int right = left + childWidth;

        child.layout(left, top, right, bottom);

        ypos = bottom + lp.bottomMargin;
    }

    mIsLaidOut = true;
}

From source file:be.virtualsushi.gaz.view.ActivityChooserView.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    View child = mActivityChooserContent;
    // If the default action is not visible we want to be as tall as the
    // ActionBar so if this widget is used in the latter it will look as
    // a normal action button.
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec),
            MeasureSpec.EXACTLY);//from w  w w . j av  a 2  s  .  c  o m
    measureChild(child, widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(child.getMeasuredWidth(), child.getMeasuredHeight());
}

From source file:com.bigpigs.fragments.SearchFragment.java

private Bitmap getMarkerBitmapFromView(@DrawableRes int resId) {

    View customMarkerView = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.custom_marker, null);
    ImageView markerImageView = (ImageView) customMarkerView.findViewById(R.id.marker_icon);
    markerImageView.setImageResource(resId);
    customMarkerView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    customMarkerView.layout(0, 0, customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight());
    customMarkerView.buildDrawingCache();
    Bitmap returnedBitmap = Bitmap.createBitmap(customMarkerView.getMeasuredWidth(),
            customMarkerView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC_IN);
    Drawable drawable = customMarkerView.getBackground();
    if (drawable != null)
        drawable.draw(canvas);/*from w ww  .j  a  v  a 2  s.  co  m*/
    customMarkerView.draw(canvas);
    return returnedBitmap;
}