final float scrollOffset = width > 0 ? (float) getScrollX() / width : 0; final float marginOffset = 0; int lastPos = -1;
/** * 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. */ protected void onPageScrolled() { final int scrollX = getScrollX(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth(); transformPage(child, transformPos); } }
int oldX = getScrollX(); int oldY = getScrollY(); int x = scroller.getCurrX();
@Override public void computeScroll() { if (!scroller.isFinished() && scroller.computeScrollOffset()) { int oldX = getScrollX(); int oldY = getScrollY(); int x = scroller.getCurrX(); int y = scroller.getCurrY(); if (oldX != x || oldY != y) { scrollTo(x, y); if (!pageScrolled(x)) { scroller.abortAnimation(); scrollTo(0, y); } } // Keep on drawing until the animation has finished. ViewCompat.postInvalidateOnAnimation(this); return; } // Done with scroll, clean up state. completeScroll(true); }
final int sx = getScrollX(); final int sy = getScrollY(); final int dx = x - sx;
float oldScrollX = getScrollX(); float scrollX = oldScrollX + deltaX; final int width = getClientWidth();
unableToDrag = false; double scroll = getScrollX() / getClientWidth();
private void recomputeScrollPosition(int width, int oldWidth, int margin, int oldMargin) { if (oldWidth > 0 && !items.isEmpty()) { 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()); if (!scroller.isFinished()) { // We now return to your regularly scheduled scroll, already in progress. final int newDuration = scroller.getDuration() - scroller.timePassed(); ItemInfo targetInfo = infoForPosition(currentItem); if (targetInfo != null) { scroller.startScroll(newOffsetPixels, 0, (int) (targetInfo.offset * width), 0, newDuration); } } } else { final ItemInfo ii = infoForPosition(currentItem); final float scrollOffset = ii != null ? Math.min(ii.offset, lastOffset) : 0; final int scrollPos = (int) (scrollOffset * (width - getPaddingLeft() - getPaddingRight())); if (scrollPos != getScrollX()) { completeScroll(false); scrollTo(scrollPos, getScrollY()); } } }
final int scrollX = getScrollX(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position;