Example usage for android.view View getMeasuredWidth

List of usage examples for android.view View getMeasuredWidth

Introduction

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

Prototype

public final int getMeasuredWidth() 

Source Link

Document

Like #getMeasuredWidthAndState() , but only returns the raw width component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

From source file:Main.java

public static Drawable convertViewToDrawable(View view) {
    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(spec, spec);/*from   w ww. j  ava2  s  .  c o  m*/
    view.layout(UPPER_LEFT_X, UPPER_LEFT_Y, view.getMeasuredWidth(), view.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    c.translate(-view.getScrollX(), -view.getScrollY());
    view.draw(c);
    view.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = view.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    view.destroyDrawingCache();
    return new BitmapDrawable(viewBmp);
}

From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackManager.java

public static void onPanelSlide(float slideOffset) {
    try {// www .  j ava  2s.com
        Activity activity = getInstance().getPenultimateActivity();
        if (activity != null) {
            View decorView = activity.getWindow().getDecorView();
            ViewCompat.setTranslationX(decorView, -(decorView.getMeasuredWidth() / 3.0f) * (1 - slideOffset));
        }
    } catch (Exception e) {
    }
}

From source file:Main.java

public static int getWidth(View view) {
    int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(w, h);/*ww  w.j  a va  2s. c  o  m*/
    return view.getMeasuredWidth();
}

From source file:Main.java

public static int getW(View v) {
    int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    v.measure(w, h);//w  ww.  j a va 2  s .c o m
    int width = v.getMeasuredWidth();
    return width;
}

From source file:Main.java

public static int getWidth(View view) {
    int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(w, h);/*from  w w w  .j  av a  2s.c om*/
    return (view.getMeasuredWidth());
}

From source file:Main.java

public static Bitmap convertViewToBitmap(View view) {
    view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.buildDrawingCache();/*from  www  .ja  v  a2s  .  c o  m*/
    return view.getDrawingCache();
}

From source file:Main.java

public static Bitmap getViewBitmap(View view) {
    view.setDrawingCacheEnabled(true);/*from w  ww .j a v  a  2  s.c om*/
    view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.buildDrawingCache(true);
    Bitmap bm = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false);
    return bm;
}

From source file:Main.java

public static Bitmap convertViewToBitmap(View v) {
    v.setDrawingCacheEnabled(true);//from  w w w  .j a va 2 s. c o  m
    v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());

    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false); // clear drawing cache
    return b;
}

From source file:Main.java

public static Bitmap getBitmapFromView(View view) {
    view.destroyDrawingCache();/*from   w  w w.  j  a va 2  s.co  m*/
    view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.setDrawingCacheEnabled(true);
    Bitmap bitmap = view.getDrawingCache(true);
    return bitmap;
}

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];//from   w  w w  .ja  v  a 2  s  .  c o m
    } 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;
}