Example usage for android.view View getHeight

List of usage examples for android.view View getHeight

Introduction

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

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getHeight() 

Source Link

Document

Return the height of your view.

Usage

From source file:Main.java

protected static void getViewHierarchy(View v, StringBuilder accumulatedString, int indentation) {
    // append string for the passed in view
    for (int i = 0; i < indentation; ++i) {
        accumulatedString.append("|\t");
    }/*from   w  ww.jav a 2s  . c o  m*/
    accumulatedString.append(String.format("%s : %d x %d @ (%d, %d)\n", v.getClass().toString(), v.getWidth(),
            v.getHeight(), v.getLeft(), v.getTop()));

    if (v instanceof ViewGroup) {
        ViewGroup g = (ViewGroup) v;
        ++indentation;
        for (int i = 0; i < g.getChildCount(); ++i) {
            getViewHierarchy(g.getChildAt(i), accumulatedString, indentation);
        }
    }
}

From source file:Main.java

public static void initViewWH(final View view) {
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override//from  w w  w  . j av  a 2s  .  c o  m
        public void onGlobalLayout() {
            view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            System.out.println(view + ", width: " + view.getWidth() + "; height: " + view.getHeight());
        }
    });

}

From source file:Main.java

@Deprecated
public static void initViewWH(final View view) {
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override//from  w  ww  . j  a v  a  2 s .  c  o m
        public void onGlobalLayout() {
            view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            System.out.println(view + ", width: " + view.getWidth() + "; height: " + view.getHeight());
        }
    });

}

From source file:Main.java

public static boolean isInVisisble(View view) {
    if (screenHeight == -1) {
        screenHeight = view.getContext().getResources().getDisplayMetrics().heightPixels;
        screenWidth = view.getContext().getResources().getDisplayMetrics().widthPixels;
    }//from w  ww . j  a  v  a 2  s.c  o  m

    view.getLocationOnScreen(location);
    int left = location[0];
    int top = location[1];
    int height = view.getHeight();

    //in top
    if ((top + height) < -0.5 * screenHeight) {
        return true;
    }

    //in bottom
    if (top > screenHeight + 0.5 * screenHeight) {
        return true;
    }

    return false;
}

From source file:Main.java

public static Bitmap createBitmapFromView(View view) {
    if (view instanceof ImageView) {
        Drawable drawable = ((ImageView) view).getDrawable();
        if (drawable != null && drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }//  w w  w  .ja v a2 s . c om
    }
    view.clearFocus();
    Bitmap bitmap = createBitmapSafely(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888, 1);
    if (bitmap != null) {
        synchronized (sCanvas) {
            Canvas canvas = sCanvas;
            canvas.setBitmap(bitmap);
            view.draw(canvas);
            canvas.setBitmap(null);
        }
    }
    return bitmap;
}

From source file:Main.java

private static ViewGroup.MarginLayoutParams getOrCreateMarginLayoutParams(View view) {
    ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (lp != null) {
        if (lp instanceof ViewGroup.MarginLayoutParams) {
            return (ViewGroup.MarginLayoutParams) lp;
        } else {/*  w w  w .  j a  v  a  2  s . co m*/
            return new ViewGroup.MarginLayoutParams(lp);
        }
    } else {
        return new ViewGroup.MarginLayoutParams(view.getWidth(), view.getHeight());
    }
}

From source file:com.simas.vc.helpers.Utils.java

public static Bitmap screenshot2(View v) {
    Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    v.draw(canvas);//from w  w w .ja  v  a2s .  c o m

    return b;
}

From source file:Main.java

/**
 * Adds a rectangular outline to a view. This can be useful when you want to add a shadow
 * to a transparent view. See b/16856049.
 * @param view view that the outline is added to
 * @param res The resources file.//ww w  . j  av a2s .  c o  m
 */
public static void addRectangularOutlineProvider(View view, Resources res) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ViewOutlineProvider rectOutlineProvider = new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    outline.setRect(0, 0, view.getWidth(), view.getHeight());
                }
            }
        };

        view.setOutlineProvider(rectOutlineProvider);
    }
}

From source file:Main.java

public static void shrinkToLeft(FragmentActivity activity, View view, AnimationListener listener) {

    DisplayMetrics displaymetrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int screenHeight = displaymetrics.heightPixels;
    int screenWidth = displaymetrics.widthPixels;

    AnimationSet animation = new AnimationSet(true);
    float pivotX = view.getWidth() / 2;
    float pivotY = view.getHeight() / 2;
    ScaleAnimation anim = new ScaleAnimation(1f, 0.8f, 1f, 0.8f, pivotX, pivotY);
    anim.setInterpolator(new LinearInterpolator());
    anim.setDuration(200);/* www .j a  v  a2 s.c  o m*/
    anim.setStartOffset(200);
    //anim.setFillAfter(true);
    animation.addAnimation(anim);

    TranslateAnimation animTrans = new TranslateAnimation(0.0f, (float) -(screenWidth - view.getWidth()), 0.0f,
            0.0f);
    anim.setInterpolator(new LinearInterpolator());
    animTrans.setDuration(400);
    //animTrans.setStartOffset(300);
    animation.addAnimation(animTrans);

    if (listener != null)
        animation.setAnimationListener(listener);

    view.startAnimation(animation);
}

From source file:Main.java

public static void enlargeToRight(FragmentActivity activity, View view, AnimationListener listener) {

    DisplayMetrics displaymetrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int screenHeight = displaymetrics.heightPixels;
    int screenWidth = displaymetrics.widthPixels;

    AnimationSet animation = new AnimationSet(true);
    float pivotX = view.getWidth() / 2;
    float pivotY = view.getHeight() / 2;
    ScaleAnimation anim = new ScaleAnimation(0.8f, 1f, 0.8f, 1f, pivotX, pivotY);
    anim.setInterpolator(new LinearInterpolator());
    anim.setDuration(200);// ww w .  j  av  a2s  .  co m
    anim.setStartOffset(200);
    //anim.setFillAfter(true);
    animation.addAnimation(anim);

    TranslateAnimation animTrans = new TranslateAnimation(0.0f, (float) (screenWidth - view.getWidth()), 0.0f,
            0.0f);
    anim.setInterpolator(new LinearInterpolator());
    animTrans.setDuration(400);
    //animTrans.setStartOffset(300);
    animation.addAnimation(animTrans);

    if (listener != null)
        animation.setAnimationListener(listener);

    view.startAnimation(animation);
}