Example usage for android.view View layout

List of usage examples for android.view View layout

Introduction

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

Prototype

@SuppressWarnings({ "unchecked" })
public void layout(int l, int t, int r, int b) 

Source Link

Document

Assign a size and position to a view and all of its descendants

This is the second phase of the layout mechanism.

Usage

From source file:com.android.leanlauncher.Workspace.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    Log.d(TAG, "OnLayout> " + getChildCount());
    if (getChildCount() == 0) {
        return;/*from   w  w  w .  j  ava2s .  c  o  m*/
    }

    int offsetX = mWorkspace.getMeasuredWidth();
    int offsetY = mWorkspace.getMeasuredHeight();

    // Update the viewport offsets
    mViewPort.offset(offsetX, offsetY);

    final View child = getChildAt(0);
    if (child.getVisibility() != View.GONE) {
        child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
    }
}

From source file:com.huewu.pla.lib.internal.PLAListView.java

protected void onLayoutChild(final View child, final int position, final int l, final int t, final int r,
        final int b) {
    child.layout(l, t, r, b);
}

From source file:com.example.newviewsplayground.WrappingSlidingPaneLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int width = r - l;
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();

    final int childCount = getChildCount();
    int xStart = paddingLeft;
    int nextXStart = xStart;

    if (mFirstLayout) {
        mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f;
    }/*from  w  ww  . j a  v a  2 s  . co m*/

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int childWidth = child.getMeasuredWidth();
        int offset = 0;

        if (lp.slideable) {
            final int margin = lp.leftMargin + lp.rightMargin;
            final int range = Math.min(nextXStart, childWidth - paddingRight - mOverhangSize) - xStart - margin;
            mSlideRange = range;
            lp.dimWhenOffset = xStart + (width - childWidth) + lp.leftMargin + range + childWidth / 2 > width
                    - paddingRight;
            xStart += (width - childWidth) + (int) (range * mSlideOffset) + lp.leftMargin;
        } else if (mCanSlide && mParallaxBy != 0) {
            offset = (int) ((1 - mSlideOffset) * mParallaxBy);
            xStart = nextXStart;
        } else {
            xStart = nextXStart;
        }

        final int childLeft = xStart - offset;
        final int childRight = childLeft + childWidth;
        final int childTop = paddingTop;
        final int childBottom = childTop + child.getMeasuredHeight();
        child.layout(childLeft, paddingTop, childRight, childBottom);

        nextXStart += child.getWidth();
    }

    if (mFirstLayout) {
        if (mCanSlide) {
            if (mParallaxBy != 0) {
                parallaxOtherViews(mSlideOffset);
            }
            if (((LayoutParams) mSlideableView.getLayoutParams()).dimWhenOffset) {
                dimChildView(mSlideableView, mSlideOffset, mSliderFadeColor);
            }
        } else {
            // Reset the dim level of all children; it's irrelevant when nothing moves.
            for (int i = 0; i < childCount; i++) {
                dimChildView(getChildAt(i), 0, mSliderFadeColor);
            }
        }
        updateObscuredViewsVisibility(mSlideableView);
    }

    mFirstLayout = false;
}

From source file:com.google.android.flexbox.FlexboxHelper.java

/**
 * Place a single View when the layout direction is horizontal
 * ({@link FlexContainer#getFlexDirection()} is either {@link FlexDirection#ROW} or
 * {@link FlexDirection#ROW_REVERSE}).//  www  . jav  a  2s . c om
 *
 * @param view     the View to be placed
 * @param flexLine the {@link FlexLine} where the View belongs to
 * @param left     the left position of the View, which the View's margin is already taken
 *                 into account
 * @param top      the top position of the flex line where the View belongs to. The actual
 *                 View's top position is shifted depending on the flexWrap and alignItems
 *                 attributes
 * @param right    the right position of the View, which the View's margin is already taken
 *                 into account
 * @param bottom   the bottom position of the flex line where the View belongs to. The actual
 *                 View's bottom position is shifted depending on the flexWrap and alignItems
 *                 attributes
 * @see FlexContainer#getAlignItems()
 * @see FlexContainer#setAlignItems(int)
 * @see FlexItem#getAlignSelf()
 */
void layoutSingleChildHorizontal(View view, FlexLine flexLine, int left, int top, int right, int bottom) {
    FlexItem flexItem = (FlexItem) view.getLayoutParams();
    int alignItems = mFlexContainer.getAlignItems();
    if (flexItem.getAlignSelf() != AlignSelf.AUTO) {
        // Expecting the values for alignItems and mAlignSelf match except for ALIGN_SELF_AUTO.
        // Assigning the mAlignSelf value as alignItems should work.
        alignItems = flexItem.getAlignSelf();
    }
    int crossSize = flexLine.mCrossSize;
    switch (alignItems) {
    case AlignItems.FLEX_START: // Intentional fall through
    case AlignItems.STRETCH:
        if (mFlexContainer.getFlexWrap() != FlexWrap.WRAP_REVERSE) {
            view.layout(left, top + flexItem.getMarginTop(), right, bottom + flexItem.getMarginTop());
        } else {
            view.layout(left, top - flexItem.getMarginBottom(), right, bottom - flexItem.getMarginBottom());
        }
        break;
    case AlignItems.BASELINE:
        if (mFlexContainer.getFlexWrap() != FlexWrap.WRAP_REVERSE) {
            int marginTop = flexLine.mMaxBaseline - view.getBaseline();
            marginTop = Math.max(marginTop, flexItem.getMarginTop());
            view.layout(left, top + marginTop, right, bottom + marginTop);
        } else {
            int marginBottom = flexLine.mMaxBaseline - view.getMeasuredHeight() + view.getBaseline();
            marginBottom = Math.max(marginBottom, flexItem.getMarginBottom());
            view.layout(left, top - marginBottom, right, bottom - marginBottom);
        }
        break;
    case AlignItems.FLEX_END:
        if (mFlexContainer.getFlexWrap() != FlexWrap.WRAP_REVERSE) {
            view.layout(left, top + crossSize - view.getMeasuredHeight() - flexItem.getMarginBottom(), right,
                    top + crossSize - flexItem.getMarginBottom());
        } else {
            // If the flexWrap == WRAP_REVERSE, the direction of the
            // flexEnd is flipped (from top to bottom).
            view.layout(left, top - crossSize + view.getMeasuredHeight() + flexItem.getMarginTop(), right,
                    bottom - crossSize + view.getMeasuredHeight() + flexItem.getMarginTop());
        }
        break;
    case AlignItems.CENTER:
        int topFromCrossAxis = (crossSize - view.getMeasuredHeight() + flexItem.getMarginTop()
                - flexItem.getMarginBottom()) / 2;
        if (mFlexContainer.getFlexWrap() != FlexWrap.WRAP_REVERSE) {
            view.layout(left, top + topFromCrossAxis, right, top + topFromCrossAxis + view.getMeasuredHeight());
        } else {
            view.layout(left, top - topFromCrossAxis, right, top - topFromCrossAxis + view.getMeasuredHeight());
        }
        break;
    }
}

From source file:cn.emagsoftware.ui.BugFixedSlidingPaneLayout.java

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

    final int width = r - l;
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();

    final int childCount = getChildCount();
    int xStart = paddingLeft;
    int nextXStart = xStart;

    if (mFirstLayout) {
        mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f;
    }/*  ww w .  jav  a  2 s. c  om*/

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int childWidth = child.getMeasuredWidth();
        int offset = 0;

        if (lp.slideable) {
            final int margin = lp.leftMargin + lp.rightMargin;
            final int range = Math.min(nextXStart, width - paddingRight - mOverhangSize) - xStart - margin;
            mSlideRange = range;
            lp.dimWhenOffset = xStart + lp.leftMargin + range + childWidth / 2 > width - paddingRight;
            xStart += (int) (range * mSlideOffset) + lp.leftMargin;
        } else if (mCanSlide && mParallaxBy != 0) {
            offset = (int) ((1 - mSlideOffset) * mParallaxBy);
            xStart = nextXStart;
        } else {
            xStart = nextXStart;
        }

        final int childLeft = xStart - offset;
        final int childRight = childLeft + childWidth;
        final int childTop = paddingTop;
        final int childBottom = childTop + child.getMeasuredHeight();
        child.layout(childLeft, paddingTop, childRight, childBottom);

        nextXStart += child.getWidth();
    }

    if (mFirstLayout) {
        if (mCanSlide) {
            if (mParallaxBy != 0) {
                parallaxOtherViews(mSlideOffset);
            }
            if (((LayoutParams) mSlideableView.getLayoutParams()).dimWhenOffset) {
                dimChildView(mSlideableView, mSlideOffset, mSliderFadeColor);
            } else {
                dimChildView(mSlideableView, 0, mSliderFadeColor);
            }
        } else {
            // Reset the dim level of all children; it's irrelevant when nothing moves.
            for (int i = 0; i < childCount; i++) {
                dimChildView(getChildAt(i), 0, mSliderFadeColor);
            }
        }
        updateObscuredViewsVisibility(mSlideableView);
    }

    mFirstLayout = false;
}

From source file:com.cooper.redditvideo.CustomSlidingPaneLayout.java

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

    final int width = r - l;
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();

    final int childCount = getChildCount();
    int xStart = paddingLeft;
    int nextXStart = xStart;

    if (mFirstLayout) {
        mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f;
    }//from   w w w.  j a  va 2  s  . co  m

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int childWidth = child.getMeasuredWidth();
        int offset = 0;

        if (lp.slideable) {
            final int margin = lp.leftMargin + lp.rightMargin;
            final int range = Math.min(nextXStart, width - paddingRight - mOverhangSize) - xStart - margin;
            mSlideRange = range;
            lp.dimWhenOffset = xStart + lp.leftMargin + range + childWidth / 2 > width - paddingRight;
            xStart += (int) (range * mSlideOffset) + lp.leftMargin;
        } else if (mCanSlide && mParallaxBy != 0) {
            offset = (int) ((1 - mSlideOffset) * mParallaxBy);
            xStart = nextXStart;
        } else {
            xStart = nextXStart;
        }

        final int childLeft = xStart - offset;
        final int childRight = childLeft + childWidth;
        final int childTop = paddingTop;
        final int childBottom = childTop + child.getMeasuredHeight();
        child.layout(childLeft, paddingTop, childRight, childBottom);

        nextXStart += child.getWidth();
    }

    if (mFirstLayout) {
        if (mCanSlide) {
            if (mParallaxBy != 0) {
                parallaxOtherViews(mSlideOffset);
            }
            if (((LayoutParams) mSlideableView.getLayoutParams()).dimWhenOffset) {
                dimChildView(mSlideableView, mSlideOffset, mSliderFadeColor);
            }
        } else {
            // Reset the dim level of all children; it's irrelevant when nothing moves.
            for (int i = 0; i < childCount; i++) {
                dimChildView(getChildAt(i), 0, mSliderFadeColor);
            }
        }
        updateObscuredViewsVisibility(mSlideableView);
    }

    mFirstLayout = false;
}

From source file:com.android.widget.SlidingPaneLayout.java

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

    final int height = b - t;
    final int paddingTop = getPaddingTop();
    final int paddingBottom = getPaddingBottom();
    final int paddingLeft = getPaddingLeft();

    final int childCount = getChildCount();
    int yStart = paddingTop;
    int nextYStart = yStart;

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }/*from   w  ww. j a  va 2 s  .c  om*/

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int childHeight = child.getMeasuredHeight();
        int offset = 0;

        if (lp.slideable) {
            final int margin = lp.topMargin + lp.bottomMargin;
            final int range = Math.min(nextYStart, height - paddingBottom) - yStart - margin;
            mSlideRange = range;

            if (mFirstLayout) {
                switch (mState) {
                case STATE_CLOSED:
                    mSlideOffset = mCanSlide ? 0.f : 1.f;
                    break;
                case STATE_OPENED:
                    mSlideOffset = mCanSlide ? 1 - (float) mOverhangSize / mSlideRange : 1.f;
                    break;
                default: // STATE_OPENED_ENTIRELY
                    mSlideOffset = 1.f;
                    break;
                }
            }

            final int pos = (int) (range * mSlideOffset);
            yStart += pos + lp.topMargin;
            mSlideOffset = (float) pos / mSlideRange;
        } else {
            yStart = nextYStart;
        }

        final int childTop = yStart - offset;
        final int childBottom = childTop + childHeight;
        final int childLeft = paddingLeft;
        final int childRight = childLeft + child.getMeasuredWidth();
        child.layout(paddingLeft, childTop, childRight, childBottom);

        nextYStart += child.getHeight();
    }

    if (mFirstLayout) {
        updateObscuredViewsVisibility(mSlideableView);
    }

    mFirstLayout = false;
}

From source file:com.google.android.flexbox.FlexboxHelper.java

/**
 * Place a single View when the layout direction is vertical
 * ({@link FlexContainer#getFlexDirection()} is either {@link FlexDirection#COLUMN} or
 * {@link FlexDirection#COLUMN_REVERSE}).
 *
 * @param view     the View to be placed
 * @param flexLine the {@link FlexLine} where the View belongs to
 * @param isRtl    {@code true} if the layout direction is right to left, {@code false}
 *                 otherwise// w  ww.j a va 2  s .co m
 * @param left     the left position of the flex line where the View belongs to. The actual
 *                 View's left position is shifted depending on the isLayoutRtl and alignItems
 *                 attributes
 * @param top      the top position of the View, which the View's margin is already taken
 *                 into account
 * @param right    the right position of the flex line where the View belongs to. The actual
 *                 View's right position is shifted depending on the isLayoutRtl and alignItems
 *                 attributes
 * @param bottom   the bottom position of the View, which the View's margin is already taken
 *                 into account
 * @see FlexContainer#getAlignItems()
 * @see FlexContainer#setAlignItems(int)
 * @see FlexItem#getAlignSelf()
 */
void layoutSingleChildVertical(View view, FlexLine flexLine, boolean isRtl, int left, int top, int right,
        int bottom) {
    FlexItem flexItem = (FlexItem) view.getLayoutParams();
    int alignItems = mFlexContainer.getAlignItems();
    if (flexItem.getAlignSelf() != AlignSelf.AUTO) {
        // Expecting the values for alignItems and mAlignSelf match except for ALIGN_SELF_AUTO.
        // Assigning the mAlignSelf value as alignItems should work.
        alignItems = flexItem.getAlignSelf();
    }
    int crossSize = flexLine.mCrossSize;
    switch (alignItems) {
    case AlignItems.FLEX_START: // Intentional fall through
    case AlignItems.STRETCH: // Intentional fall through
    case AlignItems.BASELINE:
        if (!isRtl) {
            view.layout(left + flexItem.getMarginLeft(), top, right + flexItem.getMarginLeft(), bottom);
        } else {
            view.layout(left - flexItem.getMarginRight(), top, right - flexItem.getMarginRight(), bottom);
        }
        break;
    case AlignItems.FLEX_END:
        if (!isRtl) {
            view.layout(left + crossSize - view.getMeasuredWidth() - flexItem.getMarginRight(), top,
                    right + crossSize - view.getMeasuredWidth() - flexItem.getMarginRight(), bottom);
        } else {
            // If the flexWrap == WRAP_REVERSE, the direction of the
            // flexEnd is flipped (from left to right).
            view.layout(left - crossSize + view.getMeasuredWidth() + flexItem.getMarginLeft(), top,
                    right - crossSize + view.getMeasuredWidth() + flexItem.getMarginLeft(), bottom);
        }
        break;
    case AlignItems.CENTER:
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        int leftFromCrossAxis = (crossSize - view.getMeasuredWidth()
                + MarginLayoutParamsCompat.getMarginStart(lp) - MarginLayoutParamsCompat.getMarginEnd(lp)) / 2;
        if (!isRtl) {
            view.layout(left + leftFromCrossAxis, top, right + leftFromCrossAxis, bottom);
        } else {
            view.layout(left - leftFromCrossAxis, top, right - leftFromCrossAxis, bottom);
        }
        break;
    }
}

From source file:com.abewy.android.apps.klyph.messenger.widget.SlidingPaneLayout.java

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

    final int width = r - l;
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();

    final int childCount = getChildCount();
    int xStart = paddingLeft;
    int nextXStart = xStart;

    if (mFirstLayout) {
        mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f;
    }/*from  ww w .j ava2 s  .  c  o  m*/

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int childWidth = child.getMeasuredWidth();
        int offset = 0;

        if (lp.slideable) {
            final int margin = lp.leftMargin + lp.rightMargin;
            final int range = Math.min(nextXStart, width - paddingRight - mOverhangSize) - xStart - margin;
            mSlideRange = range;
            lp.dimWhenOffset = true;//xStart + lp.leftMargin + range + childWidth / 2 >
            //width - paddingRight;
            xStart += (int) (range * mSlideOffset) + lp.leftMargin;
        } else if (mCanSlide && mParallaxBy != 0) {
            offset = (int) ((1 - mSlideOffset) * mParallaxBy);
            xStart = nextXStart;
        } else {
            xStart = nextXStart;
        }

        final int childLeft = xStart - offset;
        final int childRight = childLeft + childWidth;
        final int childTop = paddingTop;
        final int childBottom = childTop + child.getMeasuredHeight();
        child.layout(childLeft, paddingTop, childRight, childBottom);

        nextXStart += child.getWidth();
    }

    if (mFirstLayout) {
        if (mCanSlide) {
            if (mParallaxBy != 0) {
                parallaxOtherViews(mSlideOffset);
            }
            if (((LayoutParams) mSlideableView.getLayoutParams()).dimWhenOffset) {
                dimChildView(mSlideableView, mSlideOffset, mSliderFadeColor);
            }
        } else {
            // Reset the dim level of all children; it's irrelevant when nothing moves.
            for (int i = 0; i < childCount; i++) {
                dimChildView(getChildAt(i), 0, mSliderFadeColor);
            }
        }
        updateObscuredViewsVisibility(mSlideableView);
    }

    mFirstLayout = false;
}

From source file:chan.android.app.bitwise.util.StaggeredGridView.java

final void offsetChildren(int offset) {
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        child.layout(child.getLeft(), child.getTop() + offset, child.getRight(), child.getBottom() + offset);
    }/*  w ww  .  j ava 2 s  .c  o m*/

    final int colCount = mColCount;
    for (int i = 0; i < colCount; i++) {
        mItemTops[i] += offset;
        mItemBottoms[i] += offset;
    }
}