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:app.iamin.iamin.ui.recyclerview.DividerItemDecoration.java

public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);/*  w w w . ja v a2  s  .  c  om*/
    }
}

From source file:com.manning.androidhacks.hack003.view.CascadeLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {

    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();

        child.layout(lp.x, lp.y, lp.x + child.getMeasuredWidth(), lp.y + child.getMeasuredHeight());
    }//from  w  ww . j a va  2  s. c  o m
}

From source file:MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w  w w  .  j a v  a2s. co m*/
        public void onClick(View view) {
            ((TextView) findViewById(R.id.textView)).setText("Changed at runtime!");
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
            params.leftMargin += 5;
        }
    });
}

From source file:ca.co.rufus.androidboilerplate.ui.misc.DividerItemDecoration.java

public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = (int) (parent.getPaddingLeft() + (rtl ? 0 : paddingStart));
    final int right = (int) (parent.getWidth() - parent.getPaddingRight() + (rtl ? paddingStart : 0));

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin + Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + divider.getIntrinsicHeight();
        divider.setBounds(left, top, right, bottom);
        divider.draw(c);//from w  w w. j av a2 s. c  om
    }
}

From source file:ca.co.rufus.androidboilerplate.ui.misc.DividerItemDecoration.java

public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + params.rightMargin + Math.round(ViewCompat.getTranslationX(child));
        final int right = left + divider.getIntrinsicHeight();
        divider.setBounds(left, top, right, bottom);
        divider.draw(c);/*from   w ww .  ja  v  a  2 s  .  c o m*/
    }
}

From source file:cc.solart.turbo.decoration.LinearDividerItemDecoration.java

public void drawVerticalDividers(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final Drawable divider = getDivider(parent, params.getViewAdapterPosition());
        final int top = child.getBottom() + params.bottomMargin + Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + divider.getIntrinsicHeight();

        mDividerOffsets.put(params.getViewAdapterPosition(), divider.getIntrinsicHeight());

        divider.setBounds(left, top, right, bottom);
        divider.draw(c);/* w ww.ja v  a 2 s .c  o m*/
    }
}

From source file:cc.solart.turbo.decoration.LinearDividerItemDecoration.java

public void drawHorizontalDividers(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final Drawable divider = getDivider(parent, params.getViewAdapterPosition());
        final int left = child.getRight() + params.rightMargin + Math.round(ViewCompat.getTranslationX(child));
        final int right = left + divider.getIntrinsicHeight();

        mDividerOffsets.put(params.getViewAdapterPosition(), divider.getIntrinsicHeight());

        divider.setBounds(left, top, right, bottom);
        divider.draw(c);//from  www. j  av  a  2  s  .c  o m
    }
}

From source file:com.manning.androidhacks.hack003.view.CascadeLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = getPaddingLeft();
    int height = getPaddingTop();
    int verticalSpacing;

    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
        verticalSpacing = mVerticalSpacing;

        View child = getChildAt(i);
        measureChild(child, widthMeasureSpec, heightMeasureSpec);

        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        width = getPaddingLeft() + mHorizontalSpacing * i;

        lp.x = width;//from  w  w  w  . j ava  2 s.  c  o m
        lp.y = height;

        if (lp.verticalSpacing >= 0) {
            verticalSpacing = lp.verticalSpacing;
        }

        width += child.getMeasuredWidth();
        height += verticalSpacing;
    }

    width += getPaddingRight();
    height += getChildAt(getChildCount() - 1).getMeasuredHeight() + getPaddingBottom();

    setMeasuredDimension(resolveSize(width, widthMeasureSpec), resolveSize(height, heightMeasureSpec));
}

From source file:android.support.design.widget.CollapsingToolbarLayout.java

private static int getHeightWithMargins(@NonNull final View view) {
    final ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (lp instanceof MarginLayoutParams) {
        final MarginLayoutParams mlp = (MarginLayoutParams) lp;
        return view.getHeight() + mlp.topMargin + mlp.bottomMargin;
    }/*from  ww w.j a  v a 2  s.  com*/
    return view.getHeight();
}

From source file:android.support.designox.widget.HeaderScrollingViewBehavior.java

@Override
public boolean onMeasureChild(CoordinatorLayout parent, View child, int parentWidthMeasureSpec, int widthUsed,
        int parentHeightMeasureSpec, int heightUsed) {
    final int childLpHeight = child.getLayoutParams().height;
    if (childLpHeight == ViewGroup.LayoutParams.MATCH_PARENT
            || childLpHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
        // If the menu's height is set to match_parent/wrap_content then measure it
        // with the maximum visible height

        final List<View> dependencies = parent.getDependencies(child);
        final View header = findFirstDependency(dependencies);
        if (header != null) {
            if (ViewCompat.getFitsSystemWindows(header) && !ViewCompat.getFitsSystemWindows(child)) {
                // If the header is fitting system windows then we need to also,
                // otherwise we'll get CoL's compatible measuring
                ViewCompat.setFitsSystemWindows(child, true);

                if (ViewCompat.getFitsSystemWindows(child)) {
                    // If the set succeeded, trigger a new layout and return true
                    child.requestLayout();
                    return true;
                }//  w  ww .  j  a  v  a  2 s .  c  o m
            }

            if (ViewCompat.isLaidOut(header)) {
                int availableHeight = View.MeasureSpec.getSize(parentHeightMeasureSpec);
                if (availableHeight == 0) {
                    // If the measure spec doesn't specify a size, use the current height
                    availableHeight = parent.getHeight();
                }

                final int height = availableHeight - header.getMeasuredHeight() + getScrollRange(header);
                final int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height,
                        childLpHeight == ViewGroup.LayoutParams.MATCH_PARENT ? View.MeasureSpec.EXACTLY
                                : View.MeasureSpec.AT_MOST);

                // Now measure the scrolling view with the correct height
                parent.onMeasureChild(child, parentWidthMeasureSpec, widthUsed, heightMeasureSpec, heightUsed);

                return true;
            }
        }
    }
    return false;
}