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.contacts.list.ContactListItemView.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final int height = bottom - top;
    final int width = right - left;

    // Determine the vertical bounds by laying out the header first.
    int topBound = 0;
    int bottomBound = height;
    int leftBound = getPaddingLeft();
    int rightBound = width - getPaddingRight();

    final boolean isLayoutRtl = ViewUtil.isViewLayoutRtl(this);

    // Put the section header on the left side of the contact view.
    if (mIsSectionHeaderEnabled) {
        if (mHeaderView != null) {
            int headerHeight = mHeaderView.getMeasuredHeight();
            int headerTopBound = (bottomBound + topBound - headerHeight) / 2 + mTextOffsetTop;

            mHeaderView.layout(isLayoutRtl ? rightBound - mHeaderWidth : leftBound, headerTopBound,
                    isLayoutRtl ? rightBound : leftBound + mHeaderWidth, headerTopBound + headerHeight);
        }//w w w  .j  a v  a  2  s . c o m
        if (isLayoutRtl) {
            rightBound -= mHeaderWidth;
        } else {
            leftBound += mHeaderWidth;
        }
    }

    mBoundsWithoutHeader.set(left + leftBound, topBound, left + rightBound, bottomBound);
    mLeftOffset = left + leftBound;
    mRightOffset = left + rightBound;
    if (isLayoutRtl) {
        rightBound -= mGapBetweenIndexerAndImage;
    } else {
        leftBound += mGapBetweenIndexerAndImage;
    }

    if (mActivatedStateSupported && isActivated()) {
        mActivatedBackgroundDrawable.setBounds(mBoundsWithoutHeader);
    }

    if (isVisible(mCheckBox)) {
        final int photoTop = topBound + (bottomBound - topBound - mCheckBoxHeight) / 2;
        if (mPhotoPosition == PhotoPosition.LEFT) {
            mCheckBox.layout(rightBound - mGapFromScrollBar - mCheckBoxWidth, photoTop,
                    rightBound - mGapFromScrollBar, photoTop + mCheckBoxHeight);
        } else {
            mCheckBox.layout(leftBound + mGapFromScrollBar, photoTop,
                    leftBound + mGapFromScrollBar + mCheckBoxWidth, photoTop + mCheckBoxHeight);
        }
    }

    if (isVisible(mDeleteImageButton)) {
        final int photoTop = topBound + (bottomBound - topBound - mDeleteImageButtonHeight) / 2;
        final int mDeleteImageButtonSize = mDeleteImageButtonHeight > mDeleteImageButtonWidth
                ? mDeleteImageButtonHeight
                : mDeleteImageButtonWidth;
        if (mPhotoPosition == PhotoPosition.LEFT) {
            mDeleteImageButton.layout(rightBound - mDeleteImageButtonSize, photoTop, rightBound,
                    photoTop + mDeleteImageButtonSize);
            rightBound -= mDeleteImageButtonSize;
        } else {
            mDeleteImageButton.layout(leftBound, photoTop, leftBound + mDeleteImageButtonSize,
                    photoTop + mDeleteImageButtonSize);
            leftBound += mDeleteImageButtonSize;
        }
    }

    final View photoView = mQuickContact != null ? mQuickContact : mPhotoView;
    if (mPhotoPosition == PhotoPosition.LEFT) {
        // Photo is the left most view. All the other Views should on the right of the photo.
        if (photoView != null) {
            // Center the photo vertically
            final int photoTop = topBound + (bottomBound - topBound - mPhotoViewHeight) / 2 + mAvatarOffsetTop;
            photoView.layout(leftBound, photoTop, leftBound + mPhotoViewWidth, photoTop + mPhotoViewHeight);
            leftBound += mPhotoViewWidth + mGapBetweenImageAndText;
        } else if (mKeepHorizontalPaddingForPhotoView) {
            // Draw nothing but keep the padding.
            leftBound += mPhotoViewWidth + mGapBetweenImageAndText;
        }
    } else {
        // Photo is the right most view. Right bound should be adjusted that way.
        if (photoView != null) {
            // Center the photo vertically
            final int photoTop = topBound + (bottomBound - topBound - mPhotoViewHeight) / 2 + mAvatarOffsetTop;
            photoView.layout(rightBound - mPhotoViewWidth, photoTop, rightBound, photoTop + mPhotoViewHeight);
            rightBound -= (mPhotoViewWidth + mGapBetweenImageAndText);
        } else if (mKeepHorizontalPaddingForPhotoView) {
            // Draw nothing but keep the padding.
            rightBound -= (mPhotoViewWidth + mGapBetweenImageAndText);
        }

        // Add indent between left-most padding and texts.
        leftBound += mTextIndent;
    }

    if (mSupportVideoCallIcon) {
        // Place the video call button at the end of the list (e.g. take into account RTL mode).
        if (isVisible(mVideoCallIcon)) {
            // Center the video icon vertically
            final int videoIconTop = topBound + (bottomBound - topBound - mVideoCallIconSize) / 2;

            if (!isLayoutRtl) {
                // When photo is on left, video icon is placed on the right edge.
                mVideoCallIcon.layout(rightBound - mVideoCallIconSize, videoIconTop, rightBound,
                        videoIconTop + mVideoCallIconSize);
            } else {
                // When photo is on right, video icon is placed on the left edge.
                mVideoCallIcon.layout(leftBound, videoIconTop, leftBound + mVideoCallIconSize,
                        videoIconTop + mVideoCallIconSize);
            }
        }

        if (mPhotoPosition == PhotoPosition.LEFT) {
            rightBound -= (mVideoCallIconSize + mVideoCallIconMargin);
        } else {
            leftBound += mVideoCallIconSize + mVideoCallIconMargin;
        }
    }

    // Center text vertically, then apply the top offset.
    final int totalTextHeight = mNameTextViewHeight + mPhoneticNameTextViewHeight + mLabelAndDataViewMaxHeight
            + mSnippetTextViewHeight + mStatusTextViewHeight;
    int textTopBound = (bottomBound + topBound - totalTextHeight) / 2 + mTextOffsetTop;

    // Work Profile icon align top
    int workProfileIconWidth = 0;
    if (isVisible(mWorkProfileIcon)) {
        workProfileIconWidth = mWorkProfileIcon.getMeasuredWidth();
        final int distanceFromEnd = mCheckBoxWidth > 0 ? mCheckBoxWidth + mGapBetweenImageAndText : 0;
        if (mPhotoPosition == PhotoPosition.LEFT) {
            // When photo is on left, label is placed on the right edge of the list item.
            mWorkProfileIcon.layout(rightBound - workProfileIconWidth - distanceFromEnd, textTopBound,
                    rightBound - distanceFromEnd, textTopBound + mNameTextViewHeight);
        } else {
            // When photo is on right, label is placed on the left of data view.
            mWorkProfileIcon.layout(leftBound + distanceFromEnd, textTopBound,
                    leftBound + workProfileIconWidth + distanceFromEnd, textTopBound + mNameTextViewHeight);
        }
    }

    // Layout all text view and presence icon
    // Put name TextView first
    if (isVisible(mNameTextView)) {
        final int distanceFromEnd = workProfileIconWidth
                + (mCheckBoxWidth > 0 ? mCheckBoxWidth + mGapBetweenImageAndText : 0);
        if (mPhotoPosition == PhotoPosition.LEFT) {
            mNameTextView.layout(leftBound, textTopBound, rightBound - distanceFromEnd,
                    textTopBound + mNameTextViewHeight);
        } else {
            mNameTextView.layout(leftBound + distanceFromEnd, textTopBound, rightBound,
                    textTopBound + mNameTextViewHeight);
        }
    }

    if (isVisible(mNameTextView) || isVisible(mWorkProfileIcon)) {
        textTopBound += mNameTextViewHeight;
    }

    // Presence and status
    if (isLayoutRtl) {
        int statusRightBound = rightBound;
        if (isVisible(mPresenceIcon)) {
            int iconWidth = mPresenceIcon.getMeasuredWidth();
            mPresenceIcon.layout(rightBound - iconWidth, textTopBound, rightBound,
                    textTopBound + mStatusTextViewHeight);
            statusRightBound -= (iconWidth + mPresenceIconMargin);
        }

        if (isVisible(mStatusView)) {
            mStatusView.layout(leftBound, textTopBound, statusRightBound, textTopBound + mStatusTextViewHeight);
        }
    } else {
        int statusLeftBound = leftBound;
        if (isVisible(mPresenceIcon)) {
            int iconWidth = mPresenceIcon.getMeasuredWidth();
            mPresenceIcon.layout(leftBound, textTopBound, leftBound + iconWidth,
                    textTopBound + mStatusTextViewHeight);
            statusLeftBound += (iconWidth + mPresenceIconMargin);
        }

        if (isVisible(mStatusView)) {
            mStatusView.layout(statusLeftBound, textTopBound, rightBound, textTopBound + mStatusTextViewHeight);
        }
    }

    if (isVisible(mStatusView) || isVisible(mPresenceIcon)) {
        textTopBound += mStatusTextViewHeight;
    }

    // Rest of text views
    int dataLeftBound = leftBound;
    if (isVisible(mPhoneticNameTextView)) {
        mPhoneticNameTextView.layout(leftBound, textTopBound, rightBound,
                textTopBound + mPhoneticNameTextViewHeight);
        textTopBound += mPhoneticNameTextViewHeight;
    }

    // Label and Data align bottom.
    if (isVisible(mLabelView)) {
        if (!isLayoutRtl) {
            mLabelView.layout(dataLeftBound, textTopBound + mLabelAndDataViewMaxHeight - mLabelViewHeight,
                    rightBound, textTopBound + mLabelAndDataViewMaxHeight);
            dataLeftBound += mLabelView.getMeasuredWidth() + mGapBetweenLabelAndData;
        } else {
            dataLeftBound = leftBound + mLabelView.getMeasuredWidth();
            mLabelView.layout(rightBound - mLabelView.getMeasuredWidth(),
                    textTopBound + mLabelAndDataViewMaxHeight - mLabelViewHeight, rightBound,
                    textTopBound + mLabelAndDataViewMaxHeight);
            rightBound -= (mLabelView.getMeasuredWidth() + mGapBetweenLabelAndData);
        }
    }

    if (isVisible(mDataView)) {
        if (!isLayoutRtl) {
            mDataView.layout(dataLeftBound, textTopBound + mLabelAndDataViewMaxHeight - mDataViewHeight,
                    rightBound, textTopBound + mLabelAndDataViewMaxHeight);
        } else {
            mDataView.layout(rightBound - mDataView.getMeasuredWidth(),
                    textTopBound + mLabelAndDataViewMaxHeight - mDataViewHeight, rightBound,
                    textTopBound + mLabelAndDataViewMaxHeight);
        }
    }
    if (isVisible(mLabelView) || isVisible(mDataView)) {
        textTopBound += mLabelAndDataViewMaxHeight;
    }

    if (isVisible(mSnippetView)) {
        mSnippetView.layout(leftBound, textTopBound, rightBound, textTopBound + mSnippetTextViewHeight);
    }
}

From source file:org.telegram.ui.ActionBar.ActionBar.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int additionalTop = occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;

    int textLeft;
    if (backButtonImageView != null && backButtonImageView.getVisibility() != GONE) {
        backButtonImageView.layout(0, additionalTop, backButtonImageView.getMeasuredWidth(),
                additionalTop + backButtonImageView.getMeasuredHeight());
        textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 80 : 72);
    } else {/*w ww.  j av  a  2  s .  co  m*/
        textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 26 : 18);
    }

    if (menu != null && menu.getVisibility() != GONE) {
        int menuLeft = isSearchFieldVisible ? AndroidUtilities.dp(AndroidUtilities.isTablet() ? 74 : 66)
                : (right - left) - menu.getMeasuredWidth();
        menu.layout(menuLeft, additionalTop, menuLeft + menu.getMeasuredWidth(),
                additionalTop + menu.getMeasuredHeight());
    }

    if (titleTextView != null && titleTextView.getVisibility() != GONE) {
        int textTop;
        if (subtitleTextView != null && subtitleTextView.getVisibility() != GONE) {
            textTop = (getCurrentActionBarHeight() / 2 - titleTextView.getTextHeight()) / 2
                    + AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources()
                            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 2 : 3);
        } else {
            textTop = (getCurrentActionBarHeight() - titleTextView.getTextHeight()) / 2;
        }
        titleTextView.layout(textLeft, additionalTop + textTop, textLeft + titleTextView.getMeasuredWidth(),
                additionalTop + textTop + titleTextView.getTextHeight());
    }
    if (subtitleTextView != null && subtitleTextView.getVisibility() != GONE) {
        int textTop = getCurrentActionBarHeight() / 2
                + (getCurrentActionBarHeight() / 2 - subtitleTextView.getTextHeight()) / 2
                - AndroidUtilities.dp(!AndroidUtilities.isTablet()
                        && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
                                ? 1
                                : 1);
        subtitleTextView.layout(textLeft, additionalTop + textTop,
                textLeft + subtitleTextView.getMeasuredWidth(),
                additionalTop + textTop + subtitleTextView.getTextHeight());
    }

    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() == GONE || child == titleTextView || child == subtitleTextView
                || child == menu || child == backButtonImageView) {
            continue;
        }

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

        int width = child.getMeasuredWidth();
        int height = child.getMeasuredHeight();
        int childLeft;
        int childTop;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.LEFT;
        }

        final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
        final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = (right - left - width) / 2 + lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.RIGHT:
            childLeft = right - width - lp.rightMargin;
            break;
        case Gravity.LEFT:
        default:
            childLeft = lp.leftMargin;
        }

        switch (verticalGravity) {
        case Gravity.TOP:
            childTop = lp.topMargin;
            break;
        case Gravity.CENTER_VERTICAL:
            childTop = (bottom - top - height) / 2 + lp.topMargin - lp.bottomMargin;
            break;
        case Gravity.BOTTOM:
            childTop = (bottom - top) - height - lp.bottomMargin;
            break;
        default:
            childTop = lp.topMargin;
        }
        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java

private void layoutChildren() {

    int total = getTotalPages();
    int x = mPaddingLeft;

    for (int i = 0; i < total; i++) {
        View child = getScreenAt(i);

        if (null == child)
            continue;

        LayoutParams lp = child.getLayoutParams();

        // Get measure specs
        int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec, mPaddingTop + mPaddingBottom,
                lp.height);//  ww w  . j  a  v a  2s  . com
        int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec, mPaddingLeft + mPaddingRight,
                lp.width);

        // Measure child
        child.measure(childWidthSpec, childHeightSpec);

        int childLeft;
        int childRight;

        // Position vertically based on gravity setting
        int childTop = calculateTop(child, true);
        int childBottom = childTop + child.getMeasuredHeight();

        int width = child.getMeasuredWidth();
        childLeft = x;
        childRight = childLeft + width;

        child.layout(childLeft, childTop, childRight, childBottom);
        x = childRight;
    }
}

From source file:com.doubleTwist.drawerlib.ADrawerLayout.java

protected void layoutView(View v, int l, int t, int r, int b) {
    LayoutParams params = (LayoutParams) v.getLayoutParams();

    Rect bounds = new Rect();
    Rect boundsWithoutPeek = new Rect();
    int gravity = params.gravity;
    switch (gravity) {
    case Gravity.RIGHT:
        if (DEBUG)
            Log.d(TAG, "gravity: right");
        bounds.left = r - v.getMeasuredWidth() - mPeekSize.right;
        bounds.top = t;//  w  w  w  . j  a  v a2  s.co m
        bounds.right = r - mPeekSize.right;
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(mPeekSize.right, 0);
        mMinScrollX = -bounds.width();
        break;
    case Gravity.TOP:
        if (DEBUG)
            Log.d(TAG, "gravity: top");
        bounds.left = l;
        bounds.top = t + mPeekSize.top;
        bounds.right = v.getMeasuredWidth();
        bounds.bottom = t + v.getMeasuredHeight() + mPeekSize.top;
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(0, -mPeekSize.top);
        mMaxScrollY = bounds.height();
        break;
    case Gravity.BOTTOM:
        if (DEBUG)
            Log.d(TAG, "gravity: bottom");
        bounds.left = l;
        bounds.top = b - v.getMeasuredHeight() - mPeekSize.bottom;
        bounds.right = l + v.getMeasuredWidth();
        bounds.bottom = b - mPeekSize.bottom;
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(0, mPeekSize.bottom);
        mMinScrollY = -bounds.height();
        break;
    case Gravity.LEFT:
        if (DEBUG)
            Log.d(TAG, "gravity: left");
        bounds.left = l + mPeekSize.left;
        bounds.top = t;
        bounds.right = l + v.getMeasuredWidth() + mPeekSize.left;
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        mMaxScrollX = bounds.width();
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(-mPeekSize.left, 0);
        break;
    default:
        if (DEBUG)
            Log.d(TAG, "gravity: default");
        bounds.left = l;
        bounds.top = t;
        bounds.right = l + v.getMeasuredWidth();
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        break;
    }

    if (DEBUG) {
        Log.d(TAG, " == VIEW LAYOUT == " + v.toString());
        Log.d(TAG, "bounds: " + bounds.left + "," + bounds.top + "," + bounds.right + "," + bounds.bottom);
    }

    if (mLayoutBounds.containsKey(v))
        mLayoutBounds.remove(v);
    mLayoutBounds.put(v, bounds);
    if (mLayoutBoundsWithoutPeek.containsKey(v))
        mLayoutBoundsWithoutPeek.remove(v);
    mLayoutBoundsWithoutPeek.put(v, boundsWithoutPeek);
}

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

/**
 * Helper for makeAndAddView to set the position of a view and fill out its layout paramters.
 *
 * @param child    The view to position//from w  w w . j av  a2  s  . c o m
 * @param addChild true if the child should be added to the Spinner during setup
 */
private void setUpChild(View child, boolean addChild) {

    // Respect layout params that are already in the view. Otherwise
    // make some up...
    ViewGroup.LayoutParams lp = child.getLayoutParams();
    if (lp == null) {
        lp = generateDefaultLayoutParams();
    }

    if (addChild) {
        addViewInLayout(child, 0, lp);
    }

    child.setSelected(hasFocus());
    if (mDisableChildrenWhenDisabled) {
        child.setEnabled(isEnabled());
    }

    // Get measure specs
    int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec,
            mSpinnerPadding.top + mSpinnerPadding.bottom, lp.height);
    int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec,
            mSpinnerPadding.left + mSpinnerPadding.right, lp.width);

    // Measure child
    child.measure(childWidthSpec, childHeightSpec);

    int childLeft;
    int childRight;

    // Position vertically based on gravity setting
    int childTop = mSpinnerPadding.top
            + ((getMeasuredHeight() - mSpinnerPadding.bottom - mSpinnerPadding.top - child.getMeasuredHeight())
                    / 2);
    int childBottom = childTop + child.getMeasuredHeight();

    int width = child.getMeasuredWidth();
    childLeft = 0;
    childRight = childLeft + width;

    child.layout(childLeft, childTop, childRight, childBottom);
}

From source file:com.android.launcher2.PagedView.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (!mIsDataReady) {
        return;/*from  www. j  a  v  a  2 s.  c om*/
    }

    if (DEBUG)
        Log.d(TAG, "PagedView.onLayout()");
    final int verticalPadding = getPaddingTop() + getPaddingBottom();
    final int childCount = getChildCount();
    int childLeft = getRelativeChildOffset(0);

    for (int i = 0; i < childCount; i++) {
        final View child = getPageAt(i);
        if (child.getVisibility() != View.GONE) {
            final int childWidth = getScaledMeasuredWidth(child);
            final int childHeight = child.getMeasuredHeight();
            int childTop = getPaddingTop();
            if (mCenterPagesVertically) {
                childTop += ((getMeasuredHeight() - verticalPadding) - childHeight) / 2;
            }

            if (DEBUG)
                Log.d(TAG, "\tlayout-child" + i + ": " + childLeft + ", " + childTop);
            child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + childHeight);
            childLeft += childWidth + mPageSpacing;
        }
    }

    if (mFirstLayout && mCurrentPage >= 0 && mCurrentPage < getChildCount()) {
        setHorizontalScrollBarEnabled(false);
        updateCurrentPageScroll();
        setHorizontalScrollBarEnabled(true);
        mFirstLayout = false;
    }
}

From source file:org.dpadgett.timer.WorldClockFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    uiHandler = new Handler();
    final View rootView = inflater.inflate(R.layout.world_clock, container, false);
    finder = ResourceFinders.from(rootView);
    context = rootView.getContext();/*from  w  ww  .j a v  a2 s  .c  om*/
    final Button addClockButton = (Button) finder.findViewById(R.id.addClockButton);
    addClockButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View view) {
            uiHandler.post(new Runnable() {
                @Override
                public void run() {
                    newClockDialog(-1);
                }
            });
        }
    });

    clockList.clear();
    final SharedPreferences prefs = context.getSharedPreferences("WorldClocks", Context.MODE_PRIVATE);
    final int numClocks = prefs.getInt("numClocks", -1);
    if (numClocks >= 0) {
        for (int idx = 0; idx < numClocks; idx++) {
            final String clock = prefs.getString("clock" + idx, null);
            if (clock != null) {
                clockList.add(clock);
            }
        }
    } else {
        addNewClock(TimeZone.getDefault().getID(), -1);
    }

    final ListView clocksList = (ListView) finder.findViewById(R.id.clocksList);
    clocksList.setAdapter(clocksListAdapter);
    clocksList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int position,
                final long id) {
            newClockDialog(position);
        }
    });

    // hack to get the bottom divider to be the same as the listview dividers
    final Drawable divider = new ListView(context).getDivider();
    ((org.dpadgett.compat.LinearLayout) rootView).setDividerDrawable(divider);

    // forcefully pre-render content so it is cached
    rootView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            rootView.layout(0, 0, rootView.getMeasuredWidth(), rootView.getMeasuredHeight());
            rootView.draw(new Canvas(Bitmap.createBitmap(rootView.getMeasuredWidth(),
                    rootView.getMeasuredHeight(), Bitmap.Config.ARGB_8888)));
        }
    }, 1000);

    return rootView;
}

From source file:com.harry.refresh.SwipyRefreshLayout.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;/*from www  .  j a v a  2s  .co m*/
    }
    if (mTarget == null) {
        ensureTarget();
    }
    if (mTarget == null) {
        return;
    }
    final View child = mTarget;
    final int childLeft = getPaddingLeft();
    final int childTop = getPaddingTop();
    final int childWidth = width - getPaddingLeft() - getPaddingRight();
    final int childHeight = height - getPaddingTop() - getPaddingBottom();
    child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
    int circleWidth = mCircleView.getMeasuredWidth();
    int circleHeight = mCircleView.getMeasuredHeight();
    mCircleView.layout((width / 2 - circleWidth / 2), mCurrentTargetOffsetTop,
            (width / 2 + circleWidth / 2), mCurrentTargetOffsetTop + circleHeight);
}

From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
    final int width = r - l;
    final int paddingStart = getPaddingLeft();
    final int paddingEnd = getPaddingRight();
    final int paddingTop = getPaddingTop();

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

    if (mFirstLayout) {
        mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f;
    }//from  ww  w .  j  a  v a  2  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 - paddingEnd - mOverhangSize) - xStart - margin;
            mSlideRange = range;
            final int lpMargin = lp.leftMargin;
            lp.dimWhenOffset = xStart + lpMargin + range + childWidth / 2 > width - paddingEnd;
            final int pos = (int) (range * mSlideOffset);
            xStart += pos + lpMargin;
            mSlideOffset = (float) pos / mSlideRange;
        } else if (mCanSlide && mParallaxBy != 0) {
            offset = (int) ((1 - mSlideOffset) * mParallaxBy);
            xStart = nextXStart;
        } else {
            xStart = nextXStart;
        }

        final int childRight;
        final int childLeft;
        childLeft = xStart - offset;
        childRight = childLeft + childWidth;

        final int childBottom = paddingTop + child.getMeasuredHeight();
        child.layout(childLeft, paddingTop, childRight, childBottom);

        nextXStart += child.getWidth();
    }

    if (mFirstLayout) {
        if (mCanSlide) {
            if (mParallaxBy != 0) {
                parallaxOtherViews(mSlideOffset);
            }
        }
        updateObscuredViewsVisibility(mSlideableView);
    }

    mFirstLayout = false;
}

From source file:com.harry.refresh.SwipyRefreshLayout.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 ww  .  j a v  a  2  s  .co  m*/
        if (mTarget == null) {
            ensureTarget();
        }
        if (mTarget == null) {
            return;
        }
        final View child = mTarget;
        final int childLeft = getPaddingLeft();
        final int childTop = getPaddingTop();
        final int childWidth = width - getPaddingLeft() - getPaddingRight();
        final int childHeight = height - getPaddingTop() - getPaddingBottom();
        child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
        int circleWidth = mCircleView.getMeasuredWidth();
        int circleHeight = mCircleView.getMeasuredHeight();
        mCircleView.layout((width / 2 - circleWidth / 2), mCurrentTargetOffsetTop, (width / 2 + circleWidth / 2),
                mCurrentTargetOffsetTop + circleHeight);
    }