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 LayoutParams getMoveParams(View v, int upDown, int leftRight) {
    RelativeLayout.LayoutParams original = (RelativeLayout.LayoutParams) v.getLayoutParams();
    //RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(original);
    RelativeLayout.LayoutParams params = cloneParams(original);
    params.leftMargin += leftRight;/*  w w  w .  j  av  a  2 s  . c om*/
    params.rightMargin -= leftRight;
    params.topMargin -= upDown;
    params.bottomMargin += upDown;
    return params;
}

From source file:Main.java

public static void expand(final View v, int beHeight) {
    v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    v.getLayoutParams().height = 0;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override/*from w ww.j a v  a  2  s .  c o m*/
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = 350;
            v.requestLayout();
        }

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

    // 1dp/ms
    a.setDuration(500);
    v.startAnimation(a);
}

From source file:ca.rmen.android.poetassistant.main.AppBarLayoutHelper.java

private static void enableAutoHide(View view) {
    AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) view.getLayoutParams();
    params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
            | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS | AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP);
    view.setLayoutParams(params);/*w w w  .  j a va2 s  . c om*/
}

From source file:Main.java

public static void setLayoutParams(View view, int width, int height) {
    ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (lp == null) {
        lp = new ViewGroup.LayoutParams(width, height);
    } else {//from w  w  w .j a v  a 2s.c o  m
        lp.width = width;
        lp.height = height;
    }
    view.setLayoutParams(lp);
}

From source file:Main.java

private static void addDivider(final ViewGroup stripView, final View dividerView) {
    stripView.addView(dividerView);/*from w w  w . j  a v a2 s  .  c o m*/
    final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) dividerView.getLayoutParams();
    params.gravity = Gravity.CENTER;
}

From source file:Main.java

private static View addViewToAnimLayout(final View view, int[] location) {
    int x = location[0];
    int y = location[1];
    LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) view.getLayoutParams();
    lp.leftMargin = x;/*from   w  w w .j  a va  2 s  . co  m*/
    lp.topMargin = y;
    view.setLayoutParams(lp);
    return view;
}

From source file:Main.java

public static void setViewsTopMargin(View view, int topMargin) {
    if (null == view) {
        return;//from   w  w  w  . j  ava2  s  .co  m
    }

    ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
    params.topMargin = topMargin;
    view.setLayoutParams(params);
}

From source file:Main.java

public static void setMargin(View v, int left, int top, int right, int bottom, boolean horizontalWrap) {
    LinearLayout.LayoutParams layout = (LinearLayout.LayoutParams) v.getLayoutParams();
    if (layout == null) {
        // create a "default" layout
        layout = new LinearLayout.LayoutParams(
                horizontalWrap ? LayoutParams.WRAP_CONTENT : LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT);
    }/*w  ww  .  ja v a2 s  . c  o m*/
    layout.setMargins(left, top, right, bottom);
    v.setLayoutParams(layout);
}

From source file:Main.java

static int getMarginHorizontally(View v) {
    if (v == null) {
        return 0;
    }/*from   w  w w.j  av a  2  s .c o m*/
    ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
    return MarginLayoutParamsCompat.getMarginStart(lp) + MarginLayoutParamsCompat.getMarginEnd(lp);
}

From source file:Main.java

static int getMarginStart(View v) {
    if (v == null) {
        return 0;
    }//from w  ww.j  a v a 2  s.  c o m
    ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
    return MarginLayoutParamsCompat.getMarginStart(lp);
}