2018-11-26

Scroller的使用

1、初始化Scroller

Scroller mScroller = new Scroller(context);

2、重写computeScroll()方法

@Override
public void computeScroll() {
    if (mScroller.computeScrollOffset()) {
        scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
        postInvalidate();
    }
}

3、调用startScroll方法开始滑动

 private void smoothScrollTo(int destX, int destY) {
    int scrollX = getScrollX();
    int scrollY=getScrollY();
    int deltaX = destX - scrollX;
    int deltaY = destY-scrollY;
    mScroller.startScroll(scrollX, scrollY, deltaX, deltaY, 2000);
    invalidate();
}

你可能感兴趣的:(2018-11-26)