Example usage for android.view View getLayoutParams

List of usage examples for android.view View getLayoutParams

Introduction

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

Prototype

@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_")
public ViewGroup.LayoutParams getLayoutParams() 

Source Link

Document

Get the LayoutParams associated with this view.

Usage

From source file:Main.java

public static void measureView(View view, int width, int height) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (params == null) {
        params = new ViewGroup.LayoutParams(width, height);
    }// w w  w.j a va 2s.c  o m
    int mWidth = ViewGroup.getChildMeasureSpec(0, 0, params.width);

    int mHeight;
    int tempHeight = params.height;
    if (tempHeight > 0) {
        mHeight = View.MeasureSpec.makeMeasureSpec(tempHeight, View.MeasureSpec.EXACTLY);
    } else {
        mHeight = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    }
    view.measure(mWidth, mHeight);
}

From source file:Main.java

static void setLayoutWeight(final View v, final float weight, final int height) {
    final ViewGroup.LayoutParams lp = v.getLayoutParams();
    if (lp instanceof LinearLayout.LayoutParams) {
        final LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams) lp;
        llp.weight = weight;// ww  w  .j a va 2s  . com
        llp.width = 0;
        llp.height = height;
    }
}

From source file:Main.java

public static void marginForStatusBar(View view) {
    if (isCanHaveTransparentDecor()) {
        ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).topMargin += getStratusBarHeight(
                view.getContext());/* w  ww  . j a v a 2 s.  co  m*/
    }
}

From source file:Main.java

private static void setLayoutWeight(final View v, final float weight, final int height) {
    final ViewGroup.LayoutParams lp = v.getLayoutParams();
    if (lp instanceof LinearLayout.LayoutParams) {
        final LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams) lp;
        llp.weight = weight;//from   ww  w .  j a  v a 2  s . c  o m
        llp.width = 0;
        llp.height = height;
    }
}

From source file:Main.java

public static void FixScreenXY(View view, int width, int height) {
    if (view != null) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams != null) {
            layoutParams.width = width;/*from w ww .j av a 2s  .  c  o m*/
            layoutParams.height = height;
            view.setLayoutParams(layoutParams);
        }
    }
}

From source file:Main.java

public static void setWeight(View view, float weight, int orientation) {
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
    if (params == null) {
        if (orientation != LinearLayout.VERTICAL) {
            params = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT);
        } else {//from  www. ja v  a2  s .  co  m
            params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 0);
        }
    }
    params.weight = weight;
    view.setLayoutParams(params);
}

From source file:Main.java

public static void setMargins(Context context, View view, int leftDpValue, int topDpValue, int rightDpValue,
        int bottomDpValue) {
    if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.setMargins(dp2px(context, leftDpValue), dp2px(context, topDpValue),
                dp2px(context, rightDpValue), dp2px(context, bottomDpValue));
        view.requestLayout();//  w w  w.  jav  a2 s  .  c om
    }
}

From source file:Main.java

/**
 * set view height//from w  w  w .  j av  a 2s  .  c o  m
 * 
 * @param view
 * @param height
 */
public static void setViewHeight(View view, int height) {
    if (view == null) {
        return;
    }

    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.height = height;
}

From source file:Main.java

public static void marginForNavBar(View view) {
    if (isCanHaveTransparentDecor()) {
        ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).bottomMargin += getNavBarHeight(
                view.getContext());/*  ww w . ja va 2  s  .c o m*/
    }
}

From source file:Main.java

private static void setLayoutParams(View view, int width, int height, int left, int top) {
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
    layoutParams.width = width;//  ww w.  j a  va  2 s.  co m
    layoutParams.height = height;
    layoutParams.leftMargin = left;
    layoutParams.topMargin = top;

    view.setLayoutParams(layoutParams);
    view.invalidate();
}