public void onScroll(int distance) { // 杞瓙杞姩杩囩▼涓� doScroll(distance); int height = getHeight(); if (scrollingOffset > height) { scrollingOffset = height; scroller.stopScrolling(); } else if (scrollingOffset < -height) { scrollingOffset = -height; scroller.stopScrolling(); } }
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled() || getViewAdapter() == null) { return true; } switch (event.getAction()) { case MotionEvent.ACTION_MOVE: if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } break; case MotionEvent.ACTION_UP: if (!isScrollingPerformed) { int distance = (int) event.getY() - getHeight() / 2; if (distance > 0) { distance += getItemHeight() / 2; } else { distance -= getItemHeight() / 2; } int items = distance / getItemHeight(); if (items != 0 && isValidItemIndex(currentItem + items)) { notifyClickListenersAboutClick(currentItem + items); } } break; } return scroller.onTouchEvent(event); }
/** Stops scrolling */ public void stopScrolling() { scroller.stopScrolling(); }
/** * Scroll the wheel * * @param itemsToSkip items to scroll * @param time scrolling duration */ public void scroll(int itemsToScroll, int time) { int distance = itemsToScroll * getItemHeight() - scrollingOffset; scroller.scroll(distance, time); }
/** * Set the the specified scrolling interpolator * * @param interpolator the interpolator */ public void setInterpolator(Interpolator interpolator) { scroller.setInterpolator(interpolator); }
public void onJustify() { if (Math.abs(scrollingOffset) > WheelScroller.MIN_DELTA_FOR_SCROLLING) { scroller.scroll(scrollingOffset, 0); } }
/** * Scroll the spinnerwheel * * @param itemsToScroll items to scroll * @param time scrolling duration */ public void scroll(int itemsToScroll, int time) { int distance = itemsToScroll * getItemDimension() - mScrollingOffset; onScrollTouched(); // we have to emulate touch when scrolling spinnerwheel programmatically to // light up stuff mScroller.scroll(distance, time); }