/** * Check if this ViewPager can be scrolled horizontally in a certain direction. * * @param direction Negative to check scrolling left, positive to check scrolling right. * @return Whether this ViewPager can be scrolled in the specified direction. It will always * return false if the specified direction is 0. */ public boolean canScrollHorizontally(int direction) { if (mAdapter == null) { return false; } final int width = getClientWidth(); final int scrollX = getScrollX(); if (direction < 0) { return (scrollX > (int) (width * mFirstOffset)); } else if (direction > 0) { return (scrollX < (int) (width * mLastOffset)); } else { return false; } }
final int width = getClientWidth(); final float scrollOffset = width > 0 ? (float) getScrollX() / width : 0; final float marginOffset = width > 0 ? (float) mPageMargin / width : 0;
final int width = getClientWidth(); final int widthWithMargin = width + mPageMargin; final float marginOffset = (float) mPageMargin / width;
private void calculatePageOffsetsHorizontal(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) { final int N = getAdapterCount(); final int width = getClientWidth(); final float marginOffset = width > 0 ? (float) mPageMargin / width : 0;
final int width = getClientWidth();
private void scrollToItemHorizontal(int item, boolean smoothScroll, int velocity, boolean dispatchSelected) { final ItemInfo curInfo = infoForPosition(item); int destX = 0; if (curInfo != null) { final int width = getClientWidth(); destX = (int) (width * Math.max(mFirstOffset, Math.min(curInfo.offset, mLastOffset))); } if (smoothScroll) { smoothScrollToHorizontal(destX, 0, velocity); if (dispatchSelected) { dispatchOnPageSelected(item); } } else { if (dispatchSelected) { dispatchOnPageSelected(item); } completeScrollHorizontal(false); scrollTo(destX, 0); pageScrolledHorizontal(destX); } }
if (lp.isDecor) continue; final float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth(); mPageTransformer.transformPage(child, transformPos);
setScrollState(SCROLL_STATE_SETTLING); final int width = getClientWidth(); final int halfWidth = width / 2; final float distanceRatio = Math.min(1f, 1.0f * Math.abs(dx) / width);
final int clientWidth = getClientWidth();
mVelocityY = initialVelocityY; mPopulatePending = true; final int width = getClientWidth(); final int height = getClientHeight();
private void recomputeScrollPositionHorizontal(int width, int oldWidth, int margin, int oldMargin) { if (oldWidth > 0 && !mItems.isEmpty()) { if (!mScroller.isFinished()) { mScroller.setFinalX(getCurrentItem() * getClientWidth()); } else { final int widthWithMargin = width - getPaddingLeft() - getPaddingRight() + margin; final int oldWidthWithMargin = oldWidth - getPaddingLeft() - getPaddingRight() + oldMargin; final int xpos = getScrollX(); final float pageOffset = (float) xpos / oldWidthWithMargin; final int newOffsetPixels = (int) (pageOffset * widthWithMargin); scrollTo(newOffsetPixels, getScrollY()); } } else { final YViewPager.ItemInfo ii = infoForPosition(mCurItem); final float scrollOffset = ii != null ? Math.min(ii.offset, mLastOffset) : 0; final int scrollPos = (int) (scrollOffset * (width - getPaddingLeft() - getPaddingRight())); if (scrollPos != getScrollX()) { completeScrollHorizontal(false); scrollTo(scrollPos, getScrollY()); } } }