List of usage examples for android.view View offsetTopAndBottom
public void offsetTopAndBottom(int offset)
From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java
/** * This method will be invoked when the current page is scrolled, either as part * of a programmatically initiated smooth scroll or a user initiated touch scroll. * If you override this method you must call through to the superclass implementation * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled * returns./*from w ww.jav a 2s .c o m*/ * * @param position Position index of the first page currently being displayed. * Page position+1 will be visible if positionOffset is nonzero. * @param offset Value from [0, 1) indicating the offset from the page at position. * @param offsetPixels Value in pixels indicating the offset from position. */ protected void onPageScrolled(int position, float offset, int offsetPixels) { // Offset any decor views if needed - keep them on-screen at all times. if (mDecorChildCount > 0) { // BrantApps Change: Renamed scrollx to scrolly, paddingLeft to paddingTop, paddingRight to paddingBottom & width to height // BrantApps Change: Also changed method calls to get the four values final int scrollY = getScrollY(); int paddingTop = getPaddingTop(); int paddingBottom = getPaddingBottom(); final int height = getHeight(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (!lp.isDecor) continue; final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; // BrantApps Change: Renamed childLeft to childTop int childTop = 0; // BrantApps Change: In switch statement changed 3 calls to getMeasuredWidth() to getMeasuredHeight() switch (hgrav) { default: childTop = paddingTop; break; case Gravity.LEFT: childTop = paddingTop; // BrantApps Change: Was paddingLeft += child.getWidth(); paddingTop += child.getHeight(); break; case Gravity.CENTER_HORIZONTAL: childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop); break; case Gravity.RIGHT: childTop = height - paddingBottom - child.getMeasuredHeight(); paddingBottom += child.getMeasuredHeight(); break; } childTop += scrollY; // BrantApps Change: Was final int childOffset = childLeft - child.getLeft(); final int childOffset = childTop - child.getTop(); if (childOffset != 0) { child.offsetTopAndBottom(childOffset); } } } if (mOnPageChangeListener != null) { mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels); } mCalledSuper = true; }
From source file:com.ifnoif.androidtestdemo.customview.VViewPager.java
/** * This method will be invoked when the current page is scrolled, either as part * of a programmatically initiated smooth scroll or a user initiated touch scroll. * If you override this method you must call through to the superclass implementation * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled * returns.// w ww.j a v a2 s. co m * * @param position Position index of the first page currently being displayed. * Page position+1 will be visible if positionOffset is nonzero. * @param offset Value from [0, 1) indicating the offset from the page at position. * @param offsetPixels Value in pixels indicating the offset from position. */ @CallSuper protected void onPageScrolled(int position, float offset, int offsetPixels) { // Offset any decor views if needed - keep them on-screen at all times. if (mDecorChildCount > 0) { final int scrollY = getScrollY(); int paddingTop = getPaddingTop(); int paddingBottom = getPaddingBottom(); final int height = getHeight(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (!lp.isDecor) continue; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; int childTop = 0; switch (vgrav) { default: childTop = paddingTop; break; case Gravity.TOP: childTop = paddingTop; paddingTop += child.getHeight(); break; case Gravity.CENTER_VERTICAL: childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop); break; case Gravity.BOTTOM: childTop = height - paddingBottom - child.getMeasuredHeight(); paddingBottom += child.getMeasuredHeight(); break; } childTop += scrollY; final int childOffset = childTop - child.getTop(); if (childOffset != 0) { child.offsetTopAndBottom(childOffset); Log.d(TAG, "offsetTopAndBottom childOffset:" + childOffset + " tag:" + child.getTag()); } } } dispatchOnPageScrolled(position, offset, offsetPixels); if (mPageTransformer != null) { final int scrollY = getScrollY(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.isDecor) continue; final float transformPos = (float) (child.getTop() - scrollY) / getClientHeight(); mPageTransformer.transformPage(child, transformPos); Log.d(TAG, "transformPage pos:" + transformPos + " tag:" + child.getTag()); } } mCalledSuper = true; }
From source file:com.appunite.list.ListView.java
/** * Fills the grid based on positioning the new selection at a specific * location. The selection may be moved so that it does not intersect the * faded edges. The grid is then filled upwards and downwards from there. * * @param selectedTop Where the selected item should be * @param childrenTop Where to start drawing children * @param childrenBottom Last pixel where children can be drawn * @return The view that currently has selection *//* w w w . ja va 2 s. com*/ private View fillFromSelection(int selectedTop, int childrenTop, int childrenBottom) { int fadingEdgeLength = getVerticalFadingEdgeLength(); final int selectedPosition = mSelectedPosition; View sel; final int topSelectionPixel = getTopSelectionPixel(childrenTop, fadingEdgeLength, selectedPosition); final int bottomSelectionPixel = getBottomSelectionPixel(childrenBottom, fadingEdgeLength, selectedPosition); sel = makeAndAddView(selectedPosition, selectedTop, true, mListPadding.left, true); // Some of the newly selected item extends below the bottom of the list if (sel.getBottom() > bottomSelectionPixel) { // Find space available above the selection into which we can scroll // upwards final int spaceAbove = sel.getTop() - topSelectionPixel; // Find space required to bring the bottom of the selected item // fully into view final int spaceBelow = sel.getBottom() - bottomSelectionPixel; final int offset = Math.min(spaceAbove, spaceBelow); // Now offset the selected item to get it into view sel.offsetTopAndBottom(-offset); } else if (sel.getTop() < topSelectionPixel) { // Find space required to bring the top of the selected item fully // into view final int spaceAbove = topSelectionPixel - sel.getTop(); // Find space available below the selection into which we can scroll // downwards final int spaceBelow = bottomSelectionPixel - sel.getBottom(); final int offset = Math.min(spaceAbove, spaceBelow); // Offset the selected item to get it into view sel.offsetTopAndBottom(offset); } // Fill in views above and below fillAboveAndBelow(sel, selectedPosition); if (!mStackFromBottom) { correctTooHigh(getChildCount()); } else { correctTooLow(getChildCount()); } return sel; }
From source file:cn.ismartv.tvrecyclerview.widget.StaggeredGridLayoutManager.java
private void repositionToWrapContentIfNecessary() { if (mSecondaryOrientation.getMode() == View.MeasureSpec.EXACTLY) { return; // nothing to do }//from w w w .j av a 2 s . com float maxSize = 0; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); float size = mSecondaryOrientation.getDecoratedMeasurement(child); if (size < maxSize) { continue; } LayoutParams layoutParams = (LayoutParams) child.getLayoutParams(); if (layoutParams.isFullSpan()) { size = 1f * size / mSpanCount; } maxSize = Math.max(maxSize, size); } int before = mSizePerSpan; int desired = Math.round(maxSize * mSpanCount); if (mSecondaryOrientation.getMode() == View.MeasureSpec.AT_MOST) { desired = Math.min(desired, mSecondaryOrientation.getTotalSpace()); } updateMeasureSpecs(desired); if (mSizePerSpan == before) { return; // nothing has changed } for (int i = 0; i < childCount; i++) { View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.mFullSpan) { continue; } if (isLayoutRTL() && mOrientation == VERTICAL) { int newOffset = -(mSpanCount - 1 - lp.mSpan.mIndex) * mSizePerSpan; int prevOffset = -(mSpanCount - 1 - lp.mSpan.mIndex) * before; child.offsetLeftAndRight(newOffset - prevOffset); } else { int newOffset = lp.mSpan.mIndex * mSizePerSpan; int prevOffset = lp.mSpan.mIndex * before; if (mOrientation == VERTICAL) { child.offsetLeftAndRight(newOffset - prevOffset); } else { child.offsetTopAndBottom(newOffset - prevOffset); } } } }
From source file:android.improving.utils.views.cardsview.OrientedViewPager.java
/** * This method will be invoked when the current page is scrolled, either as part * of a programmatically initiated smooth scroll or a user initiated touch scroll. * If you override this method you must call through to the superclass implementation * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled * returns./*from w w w .ja va2 s. co m*/ * * @param position Position index of the first page currently being displayed. * Page position+1 will be visible if positionOffset is nonzero. * @param offset Value from [0, 1) indicating the offset from the page at position. * @param offsetPixels Value in pixels indicating the offset from position. */ protected void onPageScrolled(int position, float offset, int offsetPixels) { // Offset any decor views if needed - keep them on-screen at all times. if (mDecorChildCount > 0) { if (mOrientation == Orientation.VERTICAL) { final int scrollY = getScrollY(); int paddingTop = getPaddingTop(); int paddingBottom = getPaddingBottom(); final int height = getHeight(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (!lp.isDecor) continue; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; int childTop = 0; switch (vgrav) { default: childTop = paddingTop; break; case Gravity.TOP: childTop = paddingTop; paddingTop += child.getHeight(); break; case Gravity.CENTER_VERTICAL: childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop); break; case Gravity.BOTTOM: childTop = height - paddingBottom - child.getMeasuredHeight(); paddingBottom += child.getMeasuredHeight(); break; } childTop += scrollY; final int childOffset = childTop - child.getTop(); if (childOffset != 0) { child.offsetTopAndBottom(childOffset); } } } else { final int scrollX = getScrollX(); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); final int width = getWidth(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (!lp.isDecor) continue; final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; int childLeft = 0; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } childLeft += scrollX; final int childOffset = childLeft - child.getLeft(); if (childOffset != 0) { child.offsetLeftAndRight(childOffset); } } } } if (mOnPageChangeListener != null) { mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mPageTransformer != null) { final int scroll = (mOrientation == Orientation.VERTICAL) ? getScrollY() : getScrollX(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.isDecor) continue; final float transformPos = (float) (((mOrientation == Orientation.VERTICAL) ? child.getTop() : child.getLeft()) - scroll) / getClientSize(); mPageTransformer.transformPage(child, transformPos); } } mCalledSuper = true; }
From source file:com.appunite.list.GridView.java
/** * Add a view as a child and make sure it is measured (if necessary) and * positioned properly.//from w ww .j a va2 s . co m * * @param child The view to add * @param position The position of the view * @param y The y position relative to which this view will be positioned * @param flow if true, align top edge to y. If false, align bottom edge * to y. * @param childrenLeft Left edge where children should be positioned * @param selected Is this position selected? * @param recycled Has this view been pulled from the recycle bin? If so it * does not need to be remeasured. * @param where Where to add the item in the list * */ private void setupChild(View child, int position, int y, boolean flow, int childrenLeft, boolean selected, boolean recycled, int where) { boolean isSelected = selected && shouldShowSelector(); final boolean updateChildSelected = isSelected != child.isSelected(); final int mode = mTouchMode; final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLL && mMotionPosition == position; final boolean updateChildPressed = isPressed != child.isPressed(); boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested(); // Respect layout params that are already in the view. Otherwise make // some up... LayoutParams p = (LayoutParams) child.getLayoutParams(); if (p == null) { p = (LayoutParams) generateDefaultLayoutParams(); } p.viewType = mAdapter.getItemViewType(position); if (recycled && !p.forceAdd) { attachViewToParent(child, where, p); } else { p.forceAdd = false; addViewInLayout(child, where, p, true); } if (updateChildSelected) { child.setSelected(isSelected); if (isSelected) { requestFocus(); } } if (updateChildPressed) { child.setPressed(isPressed); } if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) { if (child instanceof Checkable) { ((Checkable) child).setChecked(mCheckStates.get(position)); } else if (getContext() .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { Compat.setActivated(child, mCheckStates.get(position)); } } if (needToMeasure) { int childHeightSpec = ViewGroup .getChildMeasureSpec(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height); int childWidthSpec = ViewGroup.getChildMeasureSpec( MeasureSpec.makeMeasureSpec(mColumnWidth, MeasureSpec.EXACTLY), 0, p.width); child.measure(childWidthSpec, childHeightSpec); } else { cleanupLayoutState(child); } final int w = child.getMeasuredWidth(); final int h = child.getMeasuredHeight(); int childLeft; final int childTop = flow ? y : y - h; final int layoutDirection = ViewCompat.getLayoutDirection(this); final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: childLeft = childrenLeft; break; case Gravity.CENTER_HORIZONTAL: childLeft = childrenLeft + ((mColumnWidth - w) / 2); break; case Gravity.RIGHT: childLeft = childrenLeft + mColumnWidth - w; break; default: childLeft = childrenLeft; break; } if (needToMeasure) { final int childRight = childLeft + w; final int childBottom = childTop + h; child.layout(childLeft, childTop, childRight, childBottom); } else { child.offsetLeftAndRight(childLeft - child.getLeft()); child.offsetTopAndBottom(childTop - child.getTop()); } if (mCachingStarted) { child.setDrawingCacheEnabled(true); } if (recycled && (((LayoutParams) child.getLayoutParams()).scrappedFromPosition) != position) { Compat.jumpDrawablesToCurrentState(child); } }
From source file:com.example.libwidgettv.bak.AbsListView.java
public void offsetChildrenTopAndBottom(int offset) { final int count = getChildCount(); for (int i = 0; i < count; i++) { final View v = getChildAt(i); v.offsetTopAndBottom(offset); }/*from ww w.j ava2 s . c o m*/ }
From source file:com.appunite.list.ListView.java
/** * Fills the list based on positioning the new selection relative to the old * selection. The new selection will be placed at, above, or below the * location of the new selection depending on how the selection is moving. * The selection will then be pinned to the visible part of the screen, * excluding the edges that are faded. The list is then filled upwards and * downwards from there.//from w w w . j a v a 2s. com * * @param oldSel The old selected view. Useful for trying to put the new * selection in the same place * @param newSel The view that is to become selected. Useful for trying to * put the new selection in the same place * @param delta Which way we are moving * @param childrenTop Where to start drawing children * @param childrenBottom Last pixel where children can be drawn * @return The view that currently has selection */ private View moveSelection(View oldSel, View newSel, int delta, int childrenTop, int childrenBottom) { int fadingEdgeLength = getVerticalFadingEdgeLength(); final int selectedPosition = mSelectedPosition; View sel; final int topSelectionPixel = getTopSelectionPixel(childrenTop, fadingEdgeLength, selectedPosition); final int bottomSelectionPixel = getBottomSelectionPixel(childrenTop, fadingEdgeLength, selectedPosition); if (delta > 0) { /* * Case 1: Scrolling down. */ /* * Before After * | | | | * +-------+ +-------+ * | A | | A | * | 1 | => +-------+ * +-------+ | B | * | B | | 2 | * +-------+ +-------+ * | | | | * * Try to keep the top of the previously selected item where it was. * oldSel = A * sel = B */ // Put oldSel (A) where it belongs oldSel = makeAndAddView(selectedPosition - 1, oldSel.getTop(), true, mListPadding.left, false); final int dividerHeight = mDividerHeight; // Now put the new selection (B) below that sel = makeAndAddView(selectedPosition, oldSel.getBottom() + dividerHeight, true, mListPadding.left, true); // Some of the newly selected item extends below the bottom of the list if (sel.getBottom() > bottomSelectionPixel) { // Find space available above the selection into which we can scroll upwards int spaceAbove = sel.getTop() - topSelectionPixel; // Find space required to bring the bottom of the selected item fully into view int spaceBelow = sel.getBottom() - bottomSelectionPixel; // Don't scroll more than half the width of the list int halfVerticalSpace = (childrenBottom - childrenTop) / 2; int offset = Math.min(spaceAbove, spaceBelow); offset = Math.min(offset, halfVerticalSpace); // We placed oldSel, so offset that item oldSel.offsetTopAndBottom(-offset); // Now offset the selected item to get it into view sel.offsetTopAndBottom(-offset); } // Fill in views above and below if (!mStackFromBottom) { fillUp(mSelectedPosition - 2, sel.getTop() - dividerHeight); adjustViewsUpOrDown(); fillDown(mSelectedPosition + 1, sel.getBottom() + dividerHeight); } else { fillDown(mSelectedPosition + 1, sel.getBottom() + dividerHeight); adjustViewsUpOrDown(); fillUp(mSelectedPosition - 2, sel.getTop() - dividerHeight); } } else if (delta < 0) { /* * Case 2: Scrolling up. */ /* * Before After * | | | | * +-------+ +-------+ * | A | | A | * +-------+ => | 1 | * | B | +-------+ * | 2 | | B | * +-------+ +-------+ * | | | | * * Try to keep the top of the item about to become selected where it was. * newSel = A * olSel = B */ if (newSel != null) { // Try to position the top of newSel (A) where it was before it was selected sel = makeAndAddView(selectedPosition, newSel.getTop(), true, mListPadding.left, true); } else { // If (A) was not on screen and so did not have a view, position // it above the oldSel (B) sel = makeAndAddView(selectedPosition, oldSel.getTop(), false, mListPadding.left, true); } // Some of the newly selected item extends above the top of the list if (sel.getTop() < topSelectionPixel) { // Find space required to bring the top of the selected item fully into view int spaceAbove = topSelectionPixel - sel.getTop(); // Find space available below the selection into which we can scroll downwards int spaceBelow = bottomSelectionPixel - sel.getBottom(); // Don't scroll more than half the width of the list int halfVerticalSpace = (childrenBottom - childrenTop) / 2; int offset = Math.min(spaceAbove, spaceBelow); offset = Math.min(offset, halfVerticalSpace); // Offset the selected item to get it into view sel.offsetTopAndBottom(offset); } // Fill in views above and below fillAboveAndBelow(sel, selectedPosition); } else { int oldTop = oldSel.getTop(); /* * Case 3: Staying still */ sel = makeAndAddView(selectedPosition, oldTop, true, mListPadding.left, true); // We're staying still... if (oldTop < childrenTop) { // ... but the top of the old selection was off screen. // (This can happen if the data changes size out from under us) int newBottom = sel.getBottom(); if (newBottom < childrenTop + 20) { // Not enough visible -- bring it onscreen sel.offsetTopAndBottom(childrenTop - sel.getTop()); } } // Fill in views above and below fillAboveAndBelow(sel, selectedPosition); } return sel; }
From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.java
/** * This method will be invoked when the current page is scrolled, either as part * of a programmatically initiated smooth scroll or a user initiated touch scroll. * If you override this method you must call through to the superclass implementation * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled * returns./* w w w .j a va 2s. com*/ * * @param position Position index of the first page currently being displayed. * Page position+1 will be visible if positionOffset is nonzero. * @param offset Value from [0, 1) indicating the offset from the page at position. * @param offsetPixels Value in pixels indicating the offset from position. */ protected void onPageScrolled(int position, float offset, int offsetPixels) { // Offset any decor views if needed - keep them on-screen at all times. if (mDecorChildCount > 0) { // TODO This is where I start getting tired. Refactor this better later. if (isOrientationHorizontal()) { final int scrollX = getScrollX(); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); final int width = getWidth(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (!lp.isDecor) continue; final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; int childLeft = 0; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } childLeft += scrollX; final int childOffset = childLeft - child.getLeft(); if (childOffset != 0) { child.offsetLeftAndRight(childOffset); } } } else { final int scrollY = getScrollY(); int paddingTop = getPaddingTop(); int paddingBottom = getPaddingBottom(); final int height = getHeight(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (!lp.isDecor) continue; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; int childTop = 0; switch (vgrav) { default: childTop = paddingTop; break; case Gravity.TOP: childTop = paddingTop; paddingTop += child.getHeight(); break; case Gravity.CENTER_VERTICAL: childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop); break; case Gravity.BOTTOM: childTop = height - paddingBottom - child.getMeasuredHeight(); paddingBottom += child.getMeasuredHeight(); break; } childTop += scrollY; final int childOffset = childTop - child.getTop(); if (childOffset != 0) { child.offsetTopAndBottom(childOffset); } } } } if (mOnPageChangeListener != null) { mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mPageTransformer != null) { final boolean horizontal = isOrientationHorizontal(); final int scroll = horizontal ? getScrollX() : getScrollY(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.isDecor) continue; float transformPos; if (horizontal) { transformPos = (float) (child.getLeft() - scroll) / getClientWidth(); } else { transformPos = (float) (child.getTop() - scroll) / getClientHeight(); } mPageTransformer.transformPage(child, transformPos); } } mCalledSuper = true; }
From source file:org.bangbang.support.v4.widget.HListView.java
/** * Add a view as a child and make sure it is measured (if necessary) and * positioned properly./*from w w w . j av a 2 s. c o m*/ * * @param child The view to add * @param position The position of this child * @param x The y position relative to which this view will be positioned * @param flowDown If true, align top edge to y. If false, align bottom * edge to y. * @param childrenLeft Left edge where children should be positioned * @param selected Is this position selected? * @param recycled Has this view been pulled from the recycle bin? If so it * does not need to be remeasured. */ private void setupChild(View child, int position, int x, boolean flowDown, int childrenTop, boolean selected, boolean recycled) { final boolean isSelected = selected && shouldShowSelector(); final boolean updateChildSelected = isSelected != child.isSelected(); final boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested(); // Respect layout params that are already in the view. Otherwise make some up... // noinspection unchecked HAbsListView.LayoutParams p = (HAbsListView.LayoutParams) child.getLayoutParams(); if (p == null) { p = new HAbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); } p.viewType = mAdapter.getItemViewType(position); if (recycled || (p.recycledHeaderFooter && p.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER)) { attachViewToParent(child, flowDown ? -1 : 0, p); } else { if (p.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) { p.recycledHeaderFooter = true; } addViewInLayout(child, flowDown ? -1 : 0, p, true); } if (updateChildSelected) { child.setSelected(isSelected); } if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) { if (child instanceof Checkable) { ((Checkable) child).setChecked(mCheckStates.get(position)); } } if (needToMeasure) { int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec, mListPadding.top + mListPadding.bottom, p.height); int lpWidth = p.width; int childWidthSpec = -1; if (lpWidth > 0) { childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, MeasureSpec.EXACTLY); } else { childWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } child.measure(childWidthSpec, childHeightSpec); } else { cleanupLayoutState(child); } final int w = child.getMeasuredWidth(); final int h = child.getMeasuredHeight(); final int childLeft = flowDown ? x : x - w; if (needToMeasure) { final int childRight = childLeft + w; final int childBottom = childrenTop + h; child.layout(childLeft, childrenTop, childRight, childBottom); } else { child.offsetLeftAndRight(childLeft - child.getLeft()); child.offsetTopAndBottom(childrenTop - child.getTop()); } if (mCachingStarted && !child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } }