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:bottombar.BottomBar.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void backgroundCircularRevealAnimation(View clickedView, final int newColor) {
    int centerX = (int) (ViewCompat.getX(clickedView) + (clickedView.getMeasuredWidth() / 2));
    int yOffset = isTabletMode ? (int) ViewCompat.getY(clickedView) : 0;
    int centerY = yOffset + clickedView.getMeasuredHeight() / 2;
    int startRadius = 0;
    int finalRadius = isTabletMode ? outerContainer.getHeight() : outerContainer.getWidth();

    Animator animator = ViewAnimationUtils.createCircularReveal(backgroundOverlay, centerX, centerY,
            startRadius, finalRadius);//from   ww  w .j av  a 2 s. c  om

    if (isTabletMode) {
        animator.setDuration(500);
    }

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            onEnd();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            onEnd();
        }

        private void onEnd() {
            outerContainer.setBackgroundColor(newColor);
            backgroundOverlay.setVisibility(View.INVISIBLE);
            ViewCompat.setAlpha(backgroundOverlay, 1);
        }
    });

    animator.start();
}

From source file:com.aretha.slidemenu.SlideMenu.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int count = getChildCount();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int statusBarHeight = mSlideMode == MODE_SLIDE_WINDOW ? STATUS_BAR_HEIGHT : 0;
    for (int index = 0; index < count; index++) {
        View child = getChildAt(index);
        final int measureWidth = child.getMeasuredWidth();
        final int measureHeight = child.getMeasuredHeight();
        LayoutParams layoutParams = (LayoutParams) child.getLayoutParams();
        switch (layoutParams.role) {
        case LayoutParams.ROLE_CONTENT:
            // we should display the content in front of all other views
            child.bringToFront();/*from   w  w w .  ja  v  a  2s .com*/
            child.layout(mCurrentContentOffset + paddingLeft, paddingTop,
                    paddingLeft + measureWidth + mCurrentContentOffset, paddingTop + measureHeight);
            break;
        case LayoutParams.ROLE_PRIMARY_MENU:
            mContentBoundsRight = measureWidth;
            child.layout(paddingLeft, statusBarHeight + paddingTop, paddingLeft + measureWidth,
                    statusBarHeight + paddingTop + measureHeight);
            break;
        case LayoutParams.ROLE_SECONDARY_MENU:
            mContentBoundsLeft = -measureWidth;
            child.layout(r - paddingRight - measureWidth, statusBarHeight + paddingTop, r - paddingRight,
                    statusBarHeight + t + measureHeight);
            break;
        default:
            continue;
        }
    }
}

From source file:com.coco.slidinguppanel.SlidingUpPanel.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (getChildCount() > 1) {
        throw new IllegalStateException("SlidingUpPanel can only contain on child view");
    } else {/*ww w.j  a v  a 2  s.  c o m*/
        int maxWidth = 0;
        int maxHeight = 0;
        if (getChildCount() == 1) {
            final View child = getChildAt(0);
            if (child.getVisibility() != GONE) {
                measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
                final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
                maxWidth = child.getMeasuredWidth() + getPaddingLeft() + getPaddingRight() + lp.leftMargin
                        + lp.rightMargin;
                maxHeight = child.getMeasuredHeight() + getPaddingTop() + getPaddingBottom() + lp.topMargin
                        + lp.bottomMargin;
            }
        }
        // Check against our minimum height and width
        maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
        maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());

        // Report our final dimensions.
        setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
                resolveSize(maxHeight, heightMeasureSpec));
    }
}

From source file:co.ceryle.segmentedbutton.SegmentedButtonGroup.java

/**
 * Crate a bitmap from the given view//from ww w. j  a  v a 2s. com
 */
private Bitmap getViewBitmap(View view) {
    // setContainerAttrs();

    //Get the dimensions of the view so we can re-layout the view at its current size
    //and create a bitmap of the same size
    int width = view.getMeasuredWidth();
    int height = view.getMeasuredHeight();

    int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
    int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);

    //Cause the view to re-layout
    view.measure(measuredWidth, measuredHeight);
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());

    //Create a bitmap backed Canvas to draw the view into
    Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);

    //Now that the view is laid out and we have a canvas, ask the view to draw itself into the canvas
    view.draw(c);
    return b;
}

From source file:com.example.guxiuzhong.pagerslidingtab_lib.PagerSlidingTabStrip.java

protected void animateFadeScale(View left, View right, float positionOffset, int position) {
    if (mState != State.IDLE) {
        if (left != null) {
            ViewHelper.setAlpha(tabViews.get(position).get("normal"), positionOffset);
            ViewHelper.setAlpha(tabViews.get(position).get("selected"), 1 - positionOffset);
            float mScale = 1 + zoomMax - zoomMax * positionOffset;
            ViewHelper.setPivotX(left, left.getMeasuredWidth() * 0.5f);
            ViewHelper.setPivotY(left, left.getMeasuredHeight() * 0.5f);
            ViewHelper.setScaleX(left, mScale);
            ViewHelper.setScaleY(left, mScale);
        }/* ww  w .  j  a v a2s .  co m*/
        if (right != null) {
            ViewHelper.setAlpha(tabViews.get(position + 1).get("normal"), 1 - positionOffset);
            ViewHelper.setAlpha(tabViews.get(position + 1).get("selected"), positionOffset);
            float mScale = 1 + zoomMax * positionOffset;
            ViewHelper.setPivotX(right, right.getMeasuredWidth() * 0.5f);
            ViewHelper.setPivotY(right, right.getMeasuredHeight() * 0.5f);
            ViewHelper.setScaleX(right, mScale);
            ViewHelper.setScaleY(right, mScale);
        }
    }
}

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

@Override
public boolean onMeasureChild(CoordinatorLayout parent, View child, int parentWidthMeasureSpec, int widthUsed,
        int parentHeightMeasureSpec, int heightUsed) {
    final int childLpHeight = child.getLayoutParams().height;
    if (childLpHeight == ViewGroup.LayoutParams.MATCH_PARENT
            || childLpHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
        // If the menu's height is set to match_parent/wrap_content then measure it
        // with the maximum visible height

        final List<View> dependencies = parent.getDependencies(child);
        final View header = findFirstDependency(dependencies);
        if (header != null) {
            if (ViewCompat.getFitsSystemWindows(header) && !ViewCompat.getFitsSystemWindows(child)) {
                // If the header is fitting system windows then we need to also,
                // otherwise we'll get CoL's compatible measuring
                ViewCompat.setFitsSystemWindows(child, true);

                if (ViewCompat.getFitsSystemWindows(child)) {
                    // If the set succeeded, trigger a new layout and return true
                    child.requestLayout();
                    return true;
                }/*w w  w  .j  ava  2 s.  c  o m*/
            }

            int availableHeight = View.MeasureSpec.getSize(parentHeightMeasureSpec);
            if (availableHeight == 0) {
                // If the measure spec doesn't specify a size, use the current height
                availableHeight = parent.getHeight();
            }

            final int height = availableHeight - header.getMeasuredHeight() + getScrollRange(header);
            final int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height,
                    childLpHeight == ViewGroup.LayoutParams.MATCH_PARENT ? View.MeasureSpec.EXACTLY
                            : View.MeasureSpec.AT_MOST);

            // Now measure the scrolling view with the correct height
            parent.onMeasureChild(child, parentWidthMeasureSpec, widthUsed, heightMeasureSpec, heightUsed);

            return true;
        }
    }
    return false;
}

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

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    LogUtils.d(TAG, "*** IN header container onLayout");

    for (View nonScrollingChild : mNonScrollingChildren) {
        if (nonScrollingChild.getVisibility() != GONE) {
            final int w = nonScrollingChild.getMeasuredWidth();
            final int h = nonScrollingChild.getMeasuredHeight();

            final MarginLayoutParams lp = (MarginLayoutParams) nonScrollingChild.getLayoutParams();

            final int childLeft = lp.leftMargin;
            final int childTop = lp.topMargin;
            nonScrollingChild.layout(childLeft, childTop, childLeft + w, childTop + h);
        }//from   w ww.ja  va 2  s  .c  o  m
    }

    if (mOverlayAdapter != null) {
        // being in a layout pass means overlay children may require measurement,
        // so invalidate them
        for (int i = 0, len = mOverlayAdapter.getCount(); i < len; i++) {
            mOverlayAdapter.getItem(i).invalidateMeasurement();
        }
    }

    positionOverlays(mOffsetY, false /* postAddView */);
}

From source file:com.adherence.adherence.SwipeRevealLayout.java

/**
 * {@inheritDoc}/* www  .jav a  2 s  . co m*/
 */
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (getChildCount() < 2) {
        throw new RuntimeException("Layout must have two children");
    }

    final LayoutParams params = getLayoutParams();

    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    int desiredWidth = 0;
    int desiredHeight = 0;

    // first find the largest child
    for (int i = 0; i < getChildCount(); i++) {
        final View child = getChildAt(i);
        measureChild(child, widthMeasureSpec, heightMeasureSpec);
        desiredWidth = Math.max(child.getMeasuredWidth(), desiredWidth);
        desiredHeight = Math.max(child.getMeasuredHeight(), desiredHeight);
    }
    // create new measure spec using the largest child width
    widthMeasureSpec = MeasureSpec.makeMeasureSpec(desiredWidth, widthMode);
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(desiredHeight, heightMode);

    final int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
    final int measuredHeight = MeasureSpec.getSize(heightMeasureSpec);

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

        if (childParams != null) {
            if (childParams.height == LayoutParams.MATCH_PARENT) {
                child.setMinimumHeight(measuredHeight);
            }

            if (childParams.width == LayoutParams.MATCH_PARENT) {
                child.setMinimumWidth(measuredWidth);
            }
        }

        measureChild(child, widthMeasureSpec, heightMeasureSpec);
        desiredWidth = Math.max(child.getMeasuredWidth(), desiredWidth);
        desiredHeight = Math.max(child.getMeasuredHeight(), desiredHeight);
    }

    // taking accounts of padding
    desiredWidth += getPaddingLeft() + getPaddingRight();
    desiredHeight += getPaddingTop() + getPaddingBottom();

    // adjust desired width
    if (widthMode == MeasureSpec.EXACTLY) {
        desiredWidth = measuredWidth;
    } else {
        if (params.width == LayoutParams.MATCH_PARENT) {
            desiredWidth = measuredWidth;
        }

        if (widthMode == MeasureSpec.AT_MOST) {
            desiredWidth = (desiredWidth > measuredWidth) ? measuredWidth : desiredWidth;
        }
    }

    // adjust desired height
    if (heightMode == MeasureSpec.EXACTLY) {
        desiredHeight = measuredHeight;
    } else {
        if (params.height == LayoutParams.MATCH_PARENT) {
            desiredHeight = measuredHeight;
        }

        if (heightMode == MeasureSpec.AT_MOST) {
            desiredHeight = (desiredHeight > measuredHeight) ? measuredHeight : desiredHeight;
        }
    }

    setMeasuredDimension(desiredWidth, desiredHeight);
}

From source file:android.support.designox.widget.HeaderScrollingViewBehavior.java

@Override
public boolean onMeasureChild(CoordinatorLayout parent, View child, int parentWidthMeasureSpec, int widthUsed,
        int parentHeightMeasureSpec, int heightUsed) {
    final int childLpHeight = child.getLayoutParams().height;
    if (childLpHeight == ViewGroup.LayoutParams.MATCH_PARENT
            || childLpHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
        // If the menu's height is set to match_parent/wrap_content then measure it
        // with the maximum visible height

        final List<View> dependencies = parent.getDependencies(child);
        final View header = findFirstDependency(dependencies);
        if (header != null) {
            if (ViewCompat.getFitsSystemWindows(header) && !ViewCompat.getFitsSystemWindows(child)) {
                // If the header is fitting system windows then we need to also,
                // otherwise we'll get CoL's compatible measuring
                ViewCompat.setFitsSystemWindows(child, true);

                if (ViewCompat.getFitsSystemWindows(child)) {
                    // If the set succeeded, trigger a new layout and return true
                    child.requestLayout();
                    return true;
                }//from  w  ww  . j a va 2 s  .c  o m
            }

            if (ViewCompat.isLaidOut(header)) {
                int availableHeight = View.MeasureSpec.getSize(parentHeightMeasureSpec);
                if (availableHeight == 0) {
                    // If the measure spec doesn't specify a size, use the current height
                    availableHeight = parent.getHeight();
                }

                final int height = availableHeight - header.getMeasuredHeight() + getScrollRange(header);
                final int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height,
                        childLpHeight == ViewGroup.LayoutParams.MATCH_PARENT ? View.MeasureSpec.EXACTLY
                                : View.MeasureSpec.AT_MOST);

                // Now measure the scrolling view with the correct height
                parent.onMeasureChild(child, parentWidthMeasureSpec, widthUsed, heightMeasureSpec, heightUsed);

                return true;
            }
        }
    }
    return false;
}

From source file:cc.softwarefactory.lokki.android.fragments.MapViewFragment.java

public Bitmap createDrawableFromView(View view) {

    Log.e(TAG, "createDrawableFromView");
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    view.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT));
    view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
    view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
    view.buildDrawingCache();/*from  w ww  . j  ava2  s . c  o m*/
    Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);

    return bitmap;
}