Scroller实现弹性滑动代码模版


Scroller scroller = new Scroller(mContext);
 
private void smoothScrollTo(int dstX, int dstY) {
    int scrollX = getScrollX();
    int delta = dstX - scrollX;
    scroller.startScroll(scrollX, 0, delta, 0, 1000);
    invalidate();
}
 
@Override
public void computeScroll() {
    if (scroller.computeScrollOffset()) {
        scrollTo(scroller.getCurrX(), scroller.getCurY());
        postInvalidate();
    }
}

你可能感兴趣的:(Scroller实现弹性滑动代码模版)