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.actionbarsherlock.internal.widget.AbsActionBarView.java

protected int positionChildInverse(View child, int x, int y, int contentHeight) {
    int childWidth = child.getMeasuredWidth();
    int childHeight = child.getMeasuredHeight();
    int childTop = y + (contentHeight - childHeight) / 2;

    child.layout(x - childWidth, childTop, x, childTop + childHeight);

    return childWidth;
}

From source file:com.cqyw.goheadlines.widget.horizonListView.HorizontalListView.java

private void positionItems(final int dx) {
    if (getChildCount() > 0) {
        mDisplayOffset += dx;/*from w  w w.ja v  a  2  s.  co  m*/
        int left = mDisplayOffset;
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            int childWidth = child.getMeasuredWidth();
            child.layout(left, 0, left + childWidth, child.getMeasuredHeight());
            left += childWidth + child.getPaddingRight();
        }
    }
}

From source file:android.support.v7.internal.widget.AbsActionBarView.java

protected int positionChild(View child, int x, int y, int contentHeight, boolean reverse) {
    int childWidth = child.getMeasuredWidth();
    int childHeight = child.getMeasuredHeight();
    int childTop = y + (contentHeight - childHeight) / 2;

    if (reverse) {
        child.layout(x - childWidth, childTop, x, childTop + childHeight);
    } else {//from   w  w w.  j  a  v  a2s.  c o  m
        child.layout(x, childTop, x + childWidth, childTop + childHeight);
    }

    return (reverse ? -childWidth : childWidth);
}

From source file:me.ele.backviewlayout.BackViewLayout.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final int width = getMeasuredWidth();
    final int height = getMeasuredHeight();
    if (getChildCount() == 0) {
        return;//  w  w  w  . j  a  v  a2s  . co  m
    }

    final int childLeft = getPaddingLeft();
    final int childTop = mCurrentTargetOffsetTop + getPaddingTop();
    final int childWidth = width - getPaddingLeft() - getPaddingRight();
    final int childHeight = height - getPaddingTop() - getPaddingBottom();

    mBackView.layout(childLeft, childTop, childLeft + mBackView.getMeasuredWidth(),
            childTop + mBackView.getMeasuredHeight());
    View content = getChildAt(1);
    if (content != null) {
        content.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
    }
}

From source file:org.mariotaku.twidere.view.CardMediaContainer.java

private void layout1Media(int[] childIndices) {
    final View child = getChildAt(childIndices[0]);
    final int left = getPaddingLeft(), top = getPaddingTop();
    final int right = left + child.getMeasuredWidth(), bottom = top + child.getMeasuredHeight();
    child.layout(left, top, right, bottom);
}

From source file:android.support.design.internal.BottomNavigationMenuView.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final int count = getChildCount();
    final int width = right - left;
    final int height = bottom - top;
    int used = 0;
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE) {
            continue;
        }/*w  ww. j  a va2  s  . c  om*/
        if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) {
            child.layout(width - used - child.getMeasuredWidth(), 0, width - used, height);
        } else {
            child.layout(used, 0, child.getMeasuredWidth() + used, height);
        }
        used += child.getMeasuredWidth();
    }
}

From source file:com.llf.nestlayout.library.NestLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int padLeft = getPaddingLeft();
    int padTop = getPaddingTop();
    int childCount = getChildCount();
    View child;
    LayoutParams lp;/*from   w  w w  .  j a  v a2  s.c o m*/
    for (int i = 0; i < childCount; i++) {
        child = getChildAt(i);
        lp = (LayoutParams) child.getLayoutParams();
        padTop += lp.topMargin;
        child.layout(padLeft + lp.leftMargin, padTop, padLeft + lp.leftMargin + child.getMeasuredWidth(),
                padTop + child.getMeasuredHeight());
        padTop += child.getMeasuredHeight() + lp.bottomMargin;
    }
}

From source file:me.philio.pinentry.PinEntryView.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    // Position the text views
    for (int i = 0; i < mDigits; i++) {
        View child = getChildAt(i);
        int left = i * mDigitWidth + (i > 0 ? i * mDigitSpacing : 0);
        child.layout(left + getPaddingLeft() + mDigitElevation, getPaddingTop() + (mDigitElevation / 2),
                left + getPaddingLeft() + mDigitElevation + mDigitWidth,
                getPaddingTop() + (mDigitElevation / 2) + mDigitHeight);
    }/*from  w  ww .  jav  a  2 s . c  o  m*/

    // Add the edit text as a 1px wide view to allow it to focus
    getChildAt(mDigits).layout(0, 0, 1, getMeasuredHeight());
}

From source file:android.support.v17.leanback.widget.DetailsOverviewSharedElementHelper.java

@Override
public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements,
        List<View> sharedElementSnapshots) {
    if (DEBUG) {//from w w w .  j  av  a2s.  com
        Log.d(TAG, "onSharedElementStart " + mActivityToRunTransition);
    }
    if (sharedElements.size() < 1) {
        return;
    }
    View overviewView = sharedElements.get(0);
    if (mViewHolder == null || mViewHolder.mOverviewFrame != overviewView) {
        return;
    }
    View snapshot = sharedElementSnapshots.get(0);
    if (hasImageViewScaleChange(snapshot)) {
        saveImageViewScale();
        changeImageViewScale(snapshot);
    }
    View imageView = mViewHolder.mImageView;
    final int width = overviewView.getWidth();
    final int height = overviewView.getHeight();
    imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
    imageView.layout(0, 0, width, height);
    final View rightPanel = mViewHolder.mRightPanel;
    if (mRightPanelWidth != 0 && mRightPanelHeight != 0) {
        rightPanel.measure(MeasureSpec.makeMeasureSpec(mRightPanelWidth, MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(mRightPanelHeight, MeasureSpec.EXACTLY));
        rightPanel.layout(width, rightPanel.getTop(), width + mRightPanelWidth,
                rightPanel.getTop() + mRightPanelHeight);
    } else {
        rightPanel.offsetLeftAndRight(width - rightPanel.getLeft());
    }
    mViewHolder.mActionsRow.setVisibility(View.INVISIBLE);
    mViewHolder.mDetailsDescriptionFrame.setVisibility(View.INVISIBLE);
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingPageView.java

/**
 * ??View?./*  w ww.jav a 2  s  .co  m*/
 *
 * @param changed the changed
 * @param l the l
 * @param t the t
 * @param r the r
 * @param b the b
 */
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    //?      
    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        int height = child.getMeasuredHeight();
        int width = child.getMeasuredWidth();
        child.setFocusable(true);
        if (D)
            Log.d(TAG, "--onLayout--:" + width);
        if (i == 0) {
            child.layout(-nextViewOffset, 0, nextViewOffset + width, height);
        } else {
            child.layout(width - nextViewOffset, 0, 2 * width - nextViewOffset, height);
        }
    }

}