public void run(){ view.scrollBy(0, scrollAmount); } });
@Override public void onAnimationUpdate(ValueAnimator animation) { int value = (int) animation.getAnimatedValue(); try { if (mScrollableView instanceof AbsListView) { scrollListBy((AbsListView) mScrollableView, value - mLastSpinner); } else { mScrollableView.scrollBy(value - mLastSpinner, 0); } } catch (Throwable ignored) { //根据用户反馈,此处可能会有BUG } mLastSpinner = value; } }
@Override public void onAnimationUpdate(ValueAnimator animation) { int value = (int) animation.getAnimatedValue(); try { if (mScrollableView instanceof AbsListView) { scrollListBy((AbsListView) mScrollableView, value - mLastSpinner); } else { mScrollableView.scrollBy(0, value - mLastSpinner); } } catch (Throwable ignored) { //根据用户反馈,此处可能会有BUG } mLastSpinner = value; } //</editor-fold>
@Override public void run() { // scroll speed. Calculated by hand. int shiftDistanceX = mDiffX / 5; int shiftDistanceY = mDiffY / 5; if ((shiftDistanceX != 0 || shiftDistanceY != 0) && !isFinished) { // change state isFinished = false; // scroll view mView.scrollBy(shiftDistanceX, shiftDistanceY); // start self again mView.post(this); } else { // have no shift distance or need to finish. stop(); } }
@Override public void run() { if (mScroller.isFinished()) { return; } // calculate offset boolean more = mScroller.computeScrollOffset(); int x = mScroller.getCurrX(); int y = mScroller.getCurrY(); int diffX = mLastX - x; int diffY = mLastY - y; if (diffX != 0 || diffY != 0) { mView.scrollBy(diffX, diffY); mLastX = x; mLastY = y; } if (more) { // run self mView.post(this); } }
@Test public void scrollBy_shouldStoreTheScrolledCoordinates() throws Exception { view.scrollTo(4, 5); view.scrollBy(10, 20); assertThat(shadowOf(view).scrollToCoordinates).isEqualTo(new Point(14, 25)); assertThat(view.getScrollX()).isEqualTo(14); assertThat(view.getScrollY()).isEqualTo(25); }
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_MOVE: int moveX = (int) event.getRawX(); int deltaX = tempX - moveX; tempX = moveX; if (moveX - downX > mTouchSlop && Math.abs((int) event.getRawY() - downY) < mTouchSlop) { isSilding = true; } if (moveX - downX >= 0 && isSilding) { mContentView.scrollBy(deltaX, 0); } break; case MotionEvent.ACTION_UP: isSilding = false; if (mContentView.getScrollX() <= -viewWidth / 2) { isFinish = true; scrollRight(); } else { scrollOrigin(); isFinish = false; } break; } return true; }
itemView.scrollBy(deltaX, 0); break; case MotionEvent.ACTION_UP:
@Override public void onDismiss() { if (mScrollDistance > 0) { int temp = mScrollDistance; mScrollDistance = 0; if (null != mContentView) { mContentView.scrollBy(0, -temp); } } } });
public void run() { view.scrollBy(0, scrollAmount); } });
public void run(){ view.scrollBy(0, scrollAmount); } });
@Override public void run() { view.scrollBy(scrollAmount, 0); } });
/** * 向右滑动 */ private void scrollRight(View item, int scorllX){ Log.e(TAG, " scroll right -> " + scorllX); item.scrollBy(scorllX, 0); }
/** * 向左滑动 */ private void scrollLeft(View item, int scorllX){ Log.e(TAG, " scroll left -> " + scorllX); item.scrollBy(scorllX, 0); }
@Override public void onAnimationUpdate(ValueAnimator animation) { dy = (int)animation.getAnimatedValue()-lastDy; lastDy = (int)animation.getAnimatedValue(); parent.scrollBy(0,dy); } });
@OnClick({ R.id.btn_scroll_to, R.id.btn_scroll_by }) public void setBtnScroll(View view) { switch (view.getId()) { case R.id.btn_scroll_to: mScrollLayout.scrollTo(DISTANCE_X, DISTANCE_Y); break; case R.id.btn_scroll_by: mScrollLayout.scrollBy(DISTANCE_X, DISTANCE_Y); break; } } }
@Override public void customScrollBy(int dy) { getView().scrollBy(0, dy); }
@Override public void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); final View viewAbove = getSlidingMenu().mViewAbove; new Handler().postDelayed(new Runnable() { @Override public void run() { viewAbove.scrollBy(-60, 0); } }, 500); new Handler().postDelayed(new Runnable() { @Override public void run() { viewAbove.scrollBy(60, 0); } }, 2000); }
public static void scrollAViewBy(View view, int height) { if (view instanceof RecyclerView) ((RecyclerView) view).scrollBy(0, height); else if (view instanceof ScrollView) ((ScrollView) view).smoothScrollBy(0, height); else if (view instanceof AbsListView) ((AbsListView) view).smoothScrollBy(height, 0); else { try { Method method = view.getClass().getDeclaredMethod("smoothScrollBy", Integer.class, Integer.class); method.invoke(view, 0, height); } catch (Exception e) { view.scrollBy(0, height); } } }
@Override public void run() { getActivity().findViewById(LongListActivity.listViewId).scrollBy(0, distance); } });