Example usage for android.view View getPaddingLeft

List of usage examples for android.view View getPaddingLeft

Introduction

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

Prototype

public int getPaddingLeft() 

Source Link

Document

Returns the left padding of this view.

Usage

From source file:Main.java

static public Rect getPaddedFrame(View v) {
    return new Rect(v.getLeft() + v.getPaddingLeft(), v.getTop() + v.getPaddingTop(),
            v.getRight() - v.getPaddingRight(), v.getBottom() - v.getPaddingBottom());
}

From source file:Main.java

public static void setBackgroundResource(final View v, final int resource) {
    final int padLeft = v.getPaddingLeft();
    final int padRight = v.getPaddingRight();
    final int padTop = v.getPaddingRight();
    final int padBottom = v.getPaddingBottom();
    v.setBackgroundResource(resource);//from  ww w  .j av  a  2s .c om
    v.setPadding(padLeft, padTop, padRight, padBottom);
}

From source file:Main.java

/**
 * Sets the background of a view to the given 9-patch resource and restores its padding. This
 * works around a bug in Android where the padding is lost when a 9-patch resource is applied
 * programmatically.//w w w . j  a  v a 2s .c  o m
 */
public static void setNinePatchBackgroundResource(View view, @DrawableRes int resource) {
    int left = view.getPaddingLeft();
    int top = view.getPaddingTop();
    int right = view.getPaddingRight();
    int bottom = view.getPaddingBottom();
    view.setBackgroundResource(resource);
    view.setPadding(left, top, right, bottom);
}

From source file:Main.java

static int getPaddingHorizontally(View v) {
    if (v == null) {
        return 0;
    }/*from w  w  w  .jav  a 2 s  . co  m*/
    return v.getPaddingLeft() + v.getPaddingRight();
}

From source file:Main.java

public static void measureDynamicHeight(View view) {
    int width = view.getWidth();
    if (width <= 0) {
        View parent = (View) view.getParent();
        width = parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight();
    }/*  w  w w.j a va2 s  .c  o m*/
    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(widthMeasureSpec, heightMeasureSpec);
}

From source file:Main.java

public static void setBackgroundKeepingPadding(View view, Drawable drawable) {
    int top = view.getPaddingTop();
    int left = view.getPaddingLeft();
    int right = view.getPaddingRight();
    int bottom = view.getPaddingBottom();

    setBackground(view, drawable);/*from w w w  .  j  a v a 2s .co  m*/
    view.setPadding(left, top, right, bottom);
}

From source file:Main.java

public static int[] getViewSizeFromSpec(View view, int widthSpec, int heightSpec) {
    int minWidth = View.MeasureSpec.getSize(widthSpec) + view.getPaddingLeft() + view.getPaddingRight();
    int width = ViewCompat.resolveSizeAndState(minWidth, widthSpec, 1);

    int minHeight = View.MeasureSpec.getSize(heightSpec) + view.getPaddingBottom() + view.getPaddingTop();
    int height = ViewCompat.resolveSizeAndState(minHeight, heightSpec, 0);
    return new int[] { width, height };
}

From source file:com.gemapps.saidit.util.ViewUtil.java

/**
 * Set a new top padding/*  w ww  .  j  a v a2  s .  co m*/
 *
 * @param view       The view to set the new top padding
 * @param paddingTop The new padding value
 */
public static void setPaddingTop(View view, int paddingTop) {

    ViewCompat.setPaddingRelative(view, view.getPaddingLeft(), paddingTop, view.getPaddingRight(),
            view.getPaddingBottom());

}

From source file:Main.java

public static void setViewBackgroundWithoutResettingPadding(final View v, final int backgroundResId) {
    final int paddingBottom = v.getPaddingBottom(), paddingLeft = v.getPaddingLeft();
    final int paddingRight = v.getPaddingRight(), paddingTop = v.getPaddingTop();
    v.setBackgroundResource(backgroundResId);
    v.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
}

From source file:Main.java

public static void setBackground(View view, int background) {
    if (view == null) {
        return;/*from   w  w w.  j a  va 2  s.  co  m*/
    }
    int left = view.getPaddingLeft();
    int right = view.getPaddingRight();
    int top = view.getPaddingTop();
    int bottom = view.getPaddingBottom();
    view.setBackgroundResource(background);
    view.setPadding(left, top, right, bottom);
}