List of usage examples for android.view View layout
@SuppressWarnings({ "unchecked" }) public void layout(int l, int t, int r, int b)
This is the second phase of the layout mechanism.
From source file:aksha.upcomingdemo.HorizontalListView.java
/** Loops through each child and positions them onto the screen */ private void positionChildren(final int dx) { int childCount = getChildCount(); if (childCount > 0) { mDisplayOffset += dx;/*w ww. ja v a2 s . co m*/ int leftOffset = mDisplayOffset; // Loop each child view for (int i = 0; i < childCount; i++) { View child = getChildAt(i); int left = leftOffset + getPaddingLeft(); int top = getPaddingTop(); int right = left + child.getMeasuredWidth(); int bottom = top + child.getMeasuredHeight(); // Layout the child child.layout(left, top, right, bottom); // Increment our offset by added child's size and divider width leftOffset += child.getMeasuredWidth() + mDividerWidth; } } }
From source file:com.wiz.dev.wiztalk.view.horizontallistview.HorizontalListView.java
/** Loops through each child and positions them onto the screen */ private void positionChildren(final int dx) { int childCount = getChildCount(); if (childCount > 0) { mDisplayOffset += dx;/*from ww w.j a v a2 s . c om*/ int leftOffset = mDisplayOffset; // Loop each child view for (int i = 0; i < childCount; i++) { View child = getChildAt(i); int left = leftOffset + getPaddingLeft(); int top = getPaddingTop(); int right = left + child.getMeasuredWidth(); int bottom = top + child.getMeasuredHeight(); // Layout the child child.layout(left, top, right, bottom); // Increment our offset by added child's sizeBigger and divider width leftOffset += child.getMeasuredWidth() + mDividerWidth; } } }
From source file:com.xuxian.marketpro.presentation.View.listview.PinnedSectionListView.java
/** Create shadow wrapper with a pinned view for a view at given position */ void createPinnedShadow(int position) { // try to recycle shadow PinnedSection pinnedShadow = mRecycleSection; mRecycleSection = null;/* ww w.java2 s .com*/ // create new shadow, if needed if (pinnedShadow == null) pinnedShadow = new PinnedSection(); // request new view using recycled view, if such View pinnedView = getAdapter().getView(position, pinnedShadow.view, PinnedSectionListView.this); // read layout parameters ViewGroup.LayoutParams layoutParams = (ViewGroup.LayoutParams) pinnedView.getLayoutParams(); if (layoutParams == null) { layoutParams = (ViewGroup.LayoutParams) generateDefaultLayoutParams(); pinnedView.setLayoutParams(layoutParams); } int heightMode = MeasureSpec.getMode(layoutParams.height); int heightSize = MeasureSpec.getSize(layoutParams.height); if (heightMode == MeasureSpec.UNSPECIFIED) heightMode = MeasureSpec.EXACTLY; int maxHeight = getHeight() - getListPaddingTop() - getListPaddingBottom(); if (heightSize > maxHeight) heightSize = maxHeight; // measure & layout int ws = MeasureSpec.makeMeasureSpec(getWidth() - getListPaddingLeft() - getListPaddingRight(), MeasureSpec.EXACTLY); int hs = MeasureSpec.makeMeasureSpec(heightSize, heightMode); pinnedView.measure(ws, hs); pinnedView.layout(0, 0, pinnedView.getMeasuredWidth(), pinnedView.getMeasuredHeight()); mTranslateY = 0; // initialize pinned shadow pinnedShadow.view = pinnedView; pinnedShadow.position = position; pinnedShadow.id = getAdapter().getItemId(position); // store pinned shadow mPinnedSection = pinnedShadow; }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java
/** * Create shadow wrapper with a sticky view at given position *//* w ww . j av a 2 s . c o m*/ void createStickyShadow(int position) { // recycle shadow StickyWrapper stickyViewShadow = recycledHeaderView; recycledHeaderView = null; // create new shadow, if needed if (stickyViewShadow == null) { stickyViewShadow = new StickyWrapper(); } // request new view using recycled view, if such View stickyView = getAdapter().getView(position, stickyViewShadow.view, MessageCenterListView.this); // read layout parameters LayoutParams layoutParams = (LayoutParams) stickyView.getLayoutParams(); if (layoutParams == null) { layoutParams = (LayoutParams) generateDefaultLayoutParams(); stickyView.setLayoutParams(layoutParams); } View childLayout = ((ViewGroup) stickyView).getChildAt(0); int heightMode = MeasureSpec.getMode(layoutParams.height); int heightSize = MeasureSpec.getSize(layoutParams.height); if (heightMode == MeasureSpec.UNSPECIFIED) { heightMode = MeasureSpec.EXACTLY; } int maxHeight = getHeight() - getListPaddingTop() - getListPaddingBottom(); if (heightSize > maxHeight) { heightSize = maxHeight; } // assuming left and right additional paddings are the same int ws = MeasureSpec.makeMeasureSpec(getWidth() - getListPaddingLeft() - getListPaddingRight(), MeasureSpec.EXACTLY); int hs = MeasureSpec.makeMeasureSpec(heightSize, heightMode); stickyView.measure(ws, hs); stickyView.layout(0, 0, stickyView.getMeasuredWidth(), stickyView.getMeasuredHeight()); // initialize shadow stickyViewShadow.view = stickyView; stickyViewShadow.position = position; stickyViewShadow.id = getAdapter().getItemId(position); stickyViewShadow.additionalIndent = childLayout.getPaddingLeft(); stickyWrapper = stickyViewShadow; }
From source file:com.tr4android.support.extension.widget.FloatingActionMenu.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { switch (mExpandDirection) { case EXPAND_UP: case EXPAND_DOWN: boolean expandUp = mExpandDirection == EXPAND_UP; // Consider margin and background padding to account for compatibility shadow mMainButton.getBackground().getPadding(childBackgroundPadding); LayoutParams mainButtonParamsHorizontal = (LayoutParams) mMainButton.getLayoutParams(); int addButtonY = expandUp ? b - t - mMainButton.getMeasuredHeight() + childBackgroundPadding.top + childBackgroundPadding.bottom - mainButtonParamsHorizontal.bottomMargin : mainButtonParamsHorizontal.topMargin; // Ensure mMainButton is centered on the line where the buttons should be int buttonsHorizontalCenter = mLabelsPosition == LABELS_ON_LEFT_SIDE ? r - l - mMaxButtonWidth / 2 - mainButtonParamsHorizontal.rightMargin : mMaxButtonWidth / 2 + mainButtonParamsHorizontal.leftMargin; int addButtonLeft = buttonsHorizontalCenter - (mMainButton.getMeasuredWidth() - childBackgroundPadding.left - childBackgroundPadding.right) / 2;/*from w ww .j av a 2 s. c o m*/ mMainButton.layout(addButtonLeft - childBackgroundPadding.left, addButtonY - childBackgroundPadding.top, addButtonLeft - childBackgroundPadding.left + mMainButton.getMeasuredWidth(), addButtonY - childBackgroundPadding.top + mMainButton.getMeasuredHeight()); addButtonY -= childBackgroundPadding.top; int labelsOffset = mMaxButtonWidth / 2 + mLabelsMargin; int labelsXNearButton = mLabelsPosition == LABELS_ON_LEFT_SIDE ? buttonsHorizontalCenter - labelsOffset : buttonsHorizontalCenter + labelsOffset; int nextY = expandUp ? addButtonY + childBackgroundPadding.top - mButtonSpacing : addButtonY + mMainButton.getMeasuredHeight() - childBackgroundPadding.top - childBackgroundPadding.bottom + mButtonSpacing; for (int i = mButtonsCount - 1; i >= 0; i--) { final View child = getChildAt(i); if (child == mMainButton || child.getVisibility() == GONE) continue; // Consider background padding to account for compatibility shadow child.getBackground().getPadding(childBackgroundPadding); int childX = buttonsHorizontalCenter - (child.getMeasuredWidth() - childBackgroundPadding.left - childBackgroundPadding.right) / 2; int childY = expandUp ? nextY - child.getMeasuredHeight() + childBackgroundPadding.top + childBackgroundPadding.bottom : nextY; child.layout(childX - childBackgroundPadding.left, childY - childBackgroundPadding.top, childX - childBackgroundPadding.left + child.getMeasuredWidth(), childY - childBackgroundPadding.top + child.getMeasuredHeight()); childY -= childBackgroundPadding.top; // TODO: mAnimator.prepareView(child, expandedTranslation, collapsedTranslation, mExpanded, false); if (mExpanded) { ((FloatingActionButton) child).show(); } else { ((FloatingActionButton) child).hide(); } LayoutParams params = (LayoutParams) child.getLayoutParams(); if (!params.isAnimated()) { // TODO: mAnimator.buildAnimationForView(child, visualYIndex, mExpandDirection, expandedTranslation, collapsedTranslation); params.setAnimated(true); } LabelView label = (LabelView) child.getTag(R.id.fab_label); if (label != null) { int labelXAwayFromButton = mLabelsPosition == LABELS_ON_LEFT_SIDE ? labelsXNearButton - label.getMeasuredWidth() : labelsXNearButton + label.getMeasuredWidth(); int labelLeft = mLabelsPosition == LABELS_ON_LEFT_SIDE ? labelXAwayFromButton : labelsXNearButton; int labelRight = mLabelsPosition == LABELS_ON_LEFT_SIDE ? labelsXNearButton : labelXAwayFromButton; int labelTop = childY - mLabelsVerticalOffset + (child.getMeasuredHeight() - label.getMeasuredHeight()) / 2; label.layout(labelLeft, labelTop, labelRight, labelTop + label.getMeasuredHeight()); label.setOnTouchListener(new PairedTouchListener(child)); child.setOnTouchListener(new PairedTouchListener(label)); // TODO: mAnimator.prepareView(label, expandedTranslation, collapsedTranslation, mExpanded, false); if (mExpanded) { label.setVisibility(VISIBLE); } else { label.setVisibility(GONE); } LayoutParams labelParams = (LayoutParams) label.getLayoutParams(); if (!labelParams.isAnimated()) { // TODO: mAnimator.buildAnimationForView(label, visualYIndex, mExpandDirection, expandedTranslation, collapsedTranslation); labelParams.setAnimated(true); } } nextY = expandUp ? childY + childBackgroundPadding.top - mButtonSpacing : childY + child.getMeasuredHeight() - childBackgroundPadding.top - childBackgroundPadding.right + mButtonSpacing; } break; case EXPAND_LEFT: case EXPAND_RIGHT: boolean expandLeft = mExpandDirection == EXPAND_LEFT; // Consider margin and background padding to account for compatibility shadow mMainButton.getBackground().getPadding(childBackgroundPadding); LayoutParams mainButtonParamsVertical = (LayoutParams) mMainButton.getLayoutParams(); int addButtonX = expandLeft ? r - l - mMainButton.getMeasuredWidth() + childBackgroundPadding.right - mainButtonParamsVertical.rightMargin : mainButtonParamsVertical.leftMargin - childBackgroundPadding.left; // Ensure mMainButton is centered on the line where the buttons should be int addButtonTop = b - t - mMaxButtonHeight + (mMaxButtonHeight - mMainButton.getMeasuredHeight() - childBackgroundPadding.top - childBackgroundPadding.bottom) / 2 - mainButtonParamsVertical.bottomMargin + childBackgroundPadding.bottom; mMainButton.layout(addButtonX, addButtonTop, addButtonX + mMainButton.getMeasuredWidth(), addButtonTop + mMainButton.getMeasuredHeight()); int nextX = expandLeft ? addButtonX + childBackgroundPadding.left - mButtonSpacing : addButtonX + mMainButton.getMeasuredWidth() - childBackgroundPadding.left - childBackgroundPadding.right + mButtonSpacing; for (int i = mButtonsCount - 1; i >= 0; i--) { final View child = getChildAt(i); if (child == mMainButton || child.getVisibility() == GONE) continue; // Consider background padding to account for compatibility shadow child.getBackground().getPadding(childBackgroundPadding); int childX = expandLeft ? nextX - child.getMeasuredWidth() + childBackgroundPadding.right : nextX - childBackgroundPadding.left; int childY = addButtonTop + (mMainButton.getMeasuredHeight() - child.getMeasuredHeight()) / 2; child.layout(childX, childY, childX + child.getMeasuredWidth(), childY + child.getMeasuredHeight()); // TODO: mAnimator.prepareView(child, expandedTranslation, collapsedTranslation, mExpanded, true); if (mExpanded) { ((FloatingActionButton) child).show(); } else { ((FloatingActionButton) child).hide(); } LayoutParams params = (LayoutParams) child.getLayoutParams(); if (!params.isAnimated()) { // TODO: mAnimator.buildAnimationForView(child, visualXIndex, mExpandDirection, expandedTranslation, collapsedTranslation); params.setAnimated(true); } nextX = expandLeft ? childX + childBackgroundPadding.left - mButtonSpacing : childX + child.getMeasuredWidth() - childBackgroundPadding.left - childBackgroundPadding.right + mButtonSpacing; } break; } }
From source file:com.comcast.freeflow.core.FreeFlowContainer.java
protected void doLayout(FreeFlowItem freeflowItem) { View view = freeflowItem.view; Rect frame = freeflowItem.frame;/* w w w.j a va2 s . com*/ view.layout(frame.left - viewPortX, frame.top - viewPortY, frame.right - viewPortX, frame.bottom - viewPortY); }
From source file:com.github.shareme.gwsstickyheadersrv.library.caching.HeaderViewCache.java
@SuppressWarnings("unchecked") @Override//from w ww . ja v a2 s .c om public View getHeader(RecyclerView parent, int position) { long headerId = mAdapter.getHeaderId(position); View header = mHeaderViews.get(headerId); if (header == null) { //TODO - recycle views RecyclerView.ViewHolder viewHolder = mAdapter.onCreateHeaderViewHolder(parent); mAdapter.onBindHeaderViewHolder(viewHolder, position); header = viewHolder.itemView; if (header.getLayoutParams() == null) { header.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } int widthSpec; int heightSpec; if (mOrientationProvider.getOrientation(parent) == LinearLayoutManager.VERTICAL) { widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED); } else { widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.UNSPECIFIED); heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.EXACTLY); } int childWidth = ViewGroup.getChildMeasureSpec(widthSpec, parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width); int childHeight = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height); header.measure(childWidth, childHeight); header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); mHeaderViews.put(headerId, header); } return header; }
From source file:com.callba.phone.widget.refreshlayout.RefreshLayout.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { final int width = right - left; final int height = bottom - top; if (getChildCount() == 0) { return;/* w ww .j a v a 2 s . c om*/ } 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), mHeaderCurrentTargetOffsetTop, (width / 2 + circleWidth / 2), mHeaderCurrentTargetOffsetTop + circleHeight); mProgressBar.setBounds(0, height - mProgressBarHeight, width, height); }
From source file:com.android.hcframe.DraggableGridViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { // Don't handle edge touches immediately -- they may actually belong to one of our // descendants. return false; }//from ww w .j ava2 s . c o m if (mPageCount <= 0) { // Nothing to present or scroll; nothing to touch. return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); final int action = ev.getAction(); boolean needsInvalidate = false; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { mScroller.abortAnimation(); // Remember where the motion event started mLastMotionX = mInitialMotionX = ev.getX(); mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); HcLog.D("Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged + " mIsUnableToDrag=" + mIsUnableToDrag); if (!mIsBeingDragged && mScrollState == SCROLL_STATE_IDLE) { mLastPosition = getPositionByXY((int) mLastMotionX, (int) mLastMotionY); } else { mLastPosition = -1; } if (mLastPosition >= 0) { mLastDownTime = System.currentTimeMillis(); } else { mLastDownTime = Long.MAX_VALUE; } HcLog.D("Down at mLastPosition=" + mLastPosition); mLastDragged = -1; break; } case MotionEvent.ACTION_MOVE: { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float y = MotionEventCompat.getY(ev, pointerIndex); if (mLastDragged >= 0) { // change draw location of dragged visual final View v = getChildAt(mLastDragged); final int l = getScrollX() + (int) x - v.getWidth() / 2; final int t = getScrollY() + (int) y - v.getHeight() / 2; v.layout(l, t, l + v.getWidth(), t + v.getHeight()); // check for new target hover if (mScrollState == SCROLL_STATE_IDLE) { final int target = getTargetByXY((int) x, (int) y); if (target != -1 && mLastTarget != target) { animateGap(target); mLastTarget = target; HcLog.D("Moved to mLastTarget=" + mLastTarget); } // edge holding final int edge = getEdgeByXY((int) x, (int) y); if (mLastEdge == -1) { if (edge != mLastEdge) { mLastEdge = edge; mLastEdgeTime = System.currentTimeMillis(); } } else { if (edge != mLastEdge) { mLastEdge = -1; } else { if ((System.currentTimeMillis() - mLastEdgeTime) >= EDGE_HOLD_DURATION) { performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); triggerSwipe(edge); mLastEdge = -1; } } } } } else if (!mIsBeingDragged) { final float xDiff = Math.abs(x - mLastMotionX); final float yDiff = Math.abs(y - mLastMotionY); HcLog.D("Moved to " + x + "," + y + " diff=" + xDiff + "," + yDiff); if (xDiff > mTouchSlop && xDiff > yDiff) { HcLog.D("Starting drag!"); mIsBeingDragged = true; requestParentDisallowInterceptTouchEvent(true); mLastMotionX = x - mInitialMotionX > 0 ? mInitialMotionX + mTouchSlop : mInitialMotionX - mTouchSlop; mLastMotionY = y; setScrollState(SCROLL_STATE_DRAGGING); setScrollingCacheEnabled(true); } } // Not else! Note that mIsBeingDragged can be set above. if (mIsBeingDragged) { // Scroll to follow the motion event needsInvalidate |= performDrag(x); } else if (mLastPosition >= 0) { final int currentPosition = getPositionByXY((int) x, (int) y); HcLog.D("Moved to currentPosition=" + currentPosition); if (currentPosition == mLastPosition) { if ((System.currentTimeMillis() - mLastDownTime) >= LONG_CLICK_DURATION) { if (onItemLongClick(currentPosition)) { performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); mLastDragged = mLastPosition; requestParentDisallowInterceptTouchEvent(true); mLastTarget = -1; animateDragged(); mLastPosition = -1; } mLastDownTime = Long.MAX_VALUE; } } else { mLastPosition = -1; } } break; } case MotionEvent.ACTION_UP: { HcLog.D("Touch up!!!"); final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float y = MotionEventCompat.getY(ev, pointerIndex); if (mLastDragged >= 0) { rearrange(); } else if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId); final int width = getWidth(); final int scrollX = getScrollX(); final int currentPage = scrollX / width; final int offsetPixels = scrollX - currentPage * width; final float pageOffset = (float) offsetPixels / (float) width; final int totalDelta = (int) (x - mInitialMotionX); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); mActivePointerId = INVALID_POINTER; endDrag(); } else if (mLastPosition >= 0) { final int currentPosition = getPositionByXY((int) x, (int) y); HcLog.D("Touch up!!! currentPosition=" + currentPosition); if (currentPosition == mLastPosition) { onItemClick(currentPosition); } } break; } case MotionEvent.ACTION_CANCEL: HcLog.D("Touch cancel!!!"); if (mLastDragged >= 0) { rearrange(); } else if (mIsBeingDragged) { scrollToItem(mCurItem, true, 0, false); mActivePointerId = INVALID_POINTER; endDrag(); } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, index); mLastMotionX = x; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } return true; }
From source file:com.base.view.slidemenu.SlideMenu.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int count = getChildCount(); final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); final int paddingTop = getPaddingTop(); final int statusBarHeight = mSlideMode == MODE_SLIDE_WINDOW ? STATUS_BAR_HEIGHT : 0; for (int index = 0; index < count; index++) { View child = getChildAt(index); final int measureWidth = child.getMeasuredWidth(); final int measureHeight = child.getMeasuredHeight(); LayoutParams layoutParams = (LayoutParams) child.getLayoutParams(); switch (layoutParams.role) { case LayoutParams.ROLE_CONTENT: // we should display the content in front of all other views child.bringToFront();// ww w . jav a 2 s .co m child.layout(mCurrentContentOffset + paddingLeft, paddingTop, paddingLeft + measureWidth + mCurrentContentOffset, paddingTop + measureHeight); break; case LayoutParams.ROLE_PRIMARY_MENU: mContentBoundsRight = measureWidth; child.layout(paddingLeft, statusBarHeight + paddingTop, paddingLeft + measureWidth, statusBarHeight + paddingTop + measureHeight); break; case LayoutParams.ROLE_SECONDARY_MENU: mContentBoundsLeft = -measureWidth; child.layout(r - l - paddingRight - measureWidth, statusBarHeight + paddingTop, r - l - paddingRight, statusBarHeight + paddingTop + measureHeight); break; default: continue; } } }