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.v7.widget.ActionBarContainer.java

private boolean isCollapsed(View view) {
    return view == null || view.getVisibility() == GONE || view.getMeasuredHeight() == 0;
}

From source file:com.eggwall.SoundSleep.SleepActivity.java

/**
 * Calculates the dimension of the entire window. Safe if called repeatedly.
 *//*w  w w  . j ava 2  s  .co m*/
private void populateTopLevelDimen() {
    if (mWidth == 0) {
        final View topLevel = findViewById(R.id.toplevel);
        mWidth = topLevel.getRight();
    }
    if (mHeight == 0) {
        final View topLevel = findViewById(R.id.toplevel);
        mHeight = topLevel.getBottom();
    }
    if (cloudSize == null) {
        final View cloud = findViewById(R.id.cloud);
        cloudSize = new Pair(cloud.getMeasuredWidth(), cloud.getMeasuredHeight());
    }
    if (noteSize == null) {
        final View note = findViewById(R.id.note);
        noteSize = new Pair(note.getMeasuredWidth(), note.getMeasuredHeight());
    }
}

From source file:com.chatwing.whitelabel.views.HeightWrappingViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST;

    if (wrapHeight) {
        /**/* w w  w .j  ava  2  s .  co m*/
         * The first super.onMeasure call made the pager take up all the
         * available height. Since we really wanted to wrap it, we need
         * to remeasure it. Luckily, after that call the first child is
         * now available. So, we take the height from it.
         */

        int width = getMeasuredWidth(), height = getMeasuredHeight();

        // Use the previously measured width but simplify the calculations
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);

        /* If the pager actually has any children, take the first child's
         * height and call that our own */
        if (getChildCount() > 0) {
            View firstChild = getChildAt(0);

            /* The child was previously measured with exactly the full height.
             * Allow it to wrap this time around. */
            firstChild.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));

            height = firstChild.getMeasuredHeight();
        }

        heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

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

private int getMeasuredHeightWithMargins(View view) {
    final LayoutParams lp = (LayoutParams) view.getLayoutParams();
    return view.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
}

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

protected int positionChild(View child, int x, int y, int contentHeight, boolean reverse) {
    int childWidth = child.getMeasuredWidth();
    int childHeight = child.getMeasuredHeight();
    int childTop = y + (contentHeight - childHeight) / 2;

    if (reverse) {
        child.layout(x - childWidth, childTop, x, childTop + childHeight);
    } else {/* w  ww  . j  av  a 2s  .com*/
        child.layout(x, childTop, x + childWidth, childTop + childHeight);
    }

    return (reverse ? -childWidth : childWidth);
}

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

protected int positionChild(View child, int x, int y, int contentHeight) {
    int childWidth = child.getMeasuredWidth();
    int childHeight = child.getMeasuredHeight();
    int childTop = y + (contentHeight - childHeight) / 2;

    child.layout(x, childTop, x + childWidth, childTop + childHeight);

    return childWidth;
}

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

protected int positionChildInverse(View child, int x, int y, int contentHeight) {
    int childWidth = child.getMeasuredWidth();
    int childHeight = child.getMeasuredHeight();
    int childTop = y + (contentHeight - childHeight) / 2;

    child.layout(x - childWidth, childTop, x, childTop + childHeight);

    return childWidth;
}

From source file:com.bamobile.fdtks.util.Tools.java

public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null)
        return;//from  ww  w.j  ava 2  s. c o  m

    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
    int totalHeight = 0;
    View view = null;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        view = listAdapter.getView(i, view, listView);
        if (i == 0)
            view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT));

        view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
        totalHeight += view.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}

From source file:com.eggwall.SoundSleep.SleepActivity.java

/**
 * Moves the clock to some random location.
 *//* w w w .  jav a2 s  .c om*/
private void changeClockLocation() {
    populateTopLevelDimen();
    final View v = findViewById(R.id.clock);
    final int x = (int) (Math.random() * (mWidth - v.getMeasuredWidth()));
    final int y = (int) (Math.random() * (mHeight - v.getMeasuredHeight()));
    if (SDK >= 12) {
        v.animate().x(x).y(y);
    } else {
        v.setPadding(x, y, 0, 0);
    }
}

From source file:cn.ieclipse.af.view.ah.AutoHeightViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int size = getChildCount();
    if (size > 0 && getLayoutParams().height == ViewGroup.LayoutParams.WRAP_CONTENT) {
        Point p = mHeights.get(getCurrentItem());
        if (p == null) {
            try {
                int i = getChildIndex();
                View child = getChildAt(i);
                if (child != null) {
                    child.measure(widthMeasureSpec,
                            MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED));
                    int w = child.getMeasuredWidth();
                    int h = child.getMeasuredHeight();
                    mHeights.put(getCurrentItem(), new Point(w, h));
                    heightMeasureSpec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY);
                    // widthMeasureSpec = MeasureSpec.makeMeasureSpec(w,
                    // MeasureSpec.EXACTLY);
                }//from  w  ww  . ja v  a  2s. c  om
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(p.y, MeasureSpec.EXACTLY);
            // widthMeasureSpec = MeasureSpec.makeMeasureSpec(p.x,
            // MeasureSpec.EXACTLY);
        }
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}