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:Main.java

public static Animation getExpandViewAnimation(final View view, int duration) {

    view.measure(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    final int targetHeight = view.getMeasuredHeight();

    view.getLayoutParams().height = 0;/*from  w ww .j a  v a  2s .c o  m*/
    view.setVisibility(View.VISIBLE);
    Animation animation = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            view.getLayoutParams().height = interpolatedTime == 1 ? RelativeLayout.LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            view.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    // animation.setDuration((int) (targetHeight /
    // view.getContext().getResources().getDisplayMetrics().density));
    animation.setDuration(duration);
    return animation;
}

From source file:Main.java

public static void updateListViewHeight(ListView listView) {
    ListAdapter mAdapter = listView.getAdapter();

    int totalHeight = 0;

    for (int i = 0; i < mAdapter.getCount(); i++) {
        View mView = mAdapter.getView(i, null, listView);

        mView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),

                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

        totalHeight += mView.getMeasuredHeight();
        //HelperMethods.log("HEIGHT" + i, String.valueOf(totalHeight));

    }/*from  ww w  . java 2  s.  com*/

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (mAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}

From source file:Main.java

public static Bitmap takeScreenshot(Activity activity, View view) {
    view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.setDrawingCacheEnabled(true);/*from  w w  w .  j  av a 2s. co m*/
    final Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false);

    return saveBitmapToFile(activity, bitmap);
}

From source file:Main.java

public static Animation collapse(final View v, int duration, boolean startAnim) {

    //check if view already gone
    if (v.getVisibility() == View.GONE)
        return null;

    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override/*  w ww  .  j a  v a2s .c om*/
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    a.setDuration(duration);
    if (startAnim)
        v.startAnimation(a);
    return a;
}

From source file:Main.java

public static int setListViewHeight(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return 0;
    }// w w  w.  j  a  va 2 s  . c o m
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        if (listItem != null) {
            listItem.measure(0, 0);
            //                CommonUtils.LOGV("samton", "listItem Height === " + listItem.getMeasuredHeight());
            totalHeight += listItem.getMeasuredHeight();
        }
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    // ((MarginLayoutParams) params).setMargins(10, 10, 10, 10);
    listView.setLayoutParams(params);
    //        CommonUtils.LOGV("samton", "totalHeight Height === " +totalHeight
    //        );
    return totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
}

From source file:Main.java

/**
 * get AbsListView height according to every children
 * /*from   w w  w. j a  v  a  2s  .c o m*/
 * @param view
 * @return
 */
public static int getAbsListViewHeightBasedOnChildren(AbsListView view) {
    ListAdapter adapter;
    if (view == null || (adapter = view.getAdapter()) == null) {
        return 0;
    }

    int height = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
        View item = adapter.getView(i, null, view);
        if (item instanceof ViewGroup) {
            item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        }
        item.measure(0, 0);
        height += item.getMeasuredHeight();
    }
    height += view.getPaddingTop() + view.getPaddingBottom();
    return height;
}

From source file:Main.java

public static int getTotalHeightofListView(ListView listView) {
    ListAdapter mAdapter = listView.getAdapter();
    if (mAdapter == null) {
        return 0;
    }/* www .  j  a  v  a 2  s . c om*/
    int totalHeight = 0;
    for (int i = 0; i < mAdapter.getCount(); i++) {
        View mView = mAdapter.getView(i, null, listView);
        mView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
        //mView.measure(0, 0);
        totalHeight += mView.getMeasuredHeight();
        Log.w("HEIGHT" + i, String.valueOf(totalHeight));
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (mAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
    return params.height;
}

From source file:Main.java

public final static int[] getPopupPosition(View anchor, int gravity) {
    int[] position = new int[2];

    int windowWidth = anchor.getRootView().getMeasuredWidth();
    int windowHeight = anchor.getRootView().getMeasuredHeight();

    int anchorWidth = anchor.getMeasuredWidth();
    int anchorHeight = anchor.getMeasuredHeight();

    int[] location = new int[2];
    anchor.getLocationInWindow(location);

    if (Gravity.LEFT == (gravity & Gravity.LEFT)) {
        position[0] = location[0];//  w w w.  j  a v  a  2  s .c om
    } else if (Gravity.RIGHT == (gravity & Gravity.RIGHT)) {
        position[0] = windowWidth - location[0] - anchorWidth;
    }

    if (Gravity.TOP == (gravity & Gravity.TOP)) {
        position[1] = location[1] + anchorHeight;
    } else if (Gravity.BOTTOM == (gravity & Gravity.BOTTOM)) {
        position[1] = windowHeight - location[1];
    }

    return position;
}

From source file:Main.java

public static int[] getMeasureViewSize(View view) {
    int size[] = new int[2];
    int width = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int height = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(width, height);//from  w w  w. j a v  a2  s  .c o  m
    size[0] = view.getMeasuredWidth();
    size[1] = view.getMeasuredHeight();
    return size;
}

From source file:Main.java

public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;/*  w w  w . ja  v  a  2  s. com*/
    }

    int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        if (listItem instanceof ViewGroup) {
            listItem.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        }
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
}