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); } }
completeScrollVertical(true); } else { completeScrollHorizontal(true);
if (dx == 0 && dy == 0) { completeScrollHorizontal(false); populateHorizontal(); setScrollState(SCROLL_STATE_IDLE);
setScrollState(SCROLL_STATE_DRAGGING); } else if (!isVertical) { completeScrollHorizontal(false); mIsBeingDragged = false; } else if (isVertical && mScrollState == SCROLL_STATE_SETTLING
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()); } } }