PageScrollTab.java 文件源码

java
阅读 35 收藏 0 点赞 0 评论 0

项目:PageScrollView 作者:
public void smoothScroll(int from, int to, Animation.AnimationListener l) {
    int childCount = getItemCount();
    if (from >= 0 && to >= 0 && (from < childCount && to < childCount)) {
        if (getAnimation() != null) {
            getAnimation().cancel();
            clearAnimation();
        }
        boolean horizontal = mOrientation == HORIZONTAL;
        int scrollFrom = computeScrollOffset(getVirtualChildAt(from, true), 0, false, horizontal);
        int scrollTo = computeScrollOffset(getVirtualChildAt(to, true), 0, false, horizontal);
        if (scrollTo != scrollFrom) {
            int absDx = Math.abs(scrollTo - scrollFrom);
            ScrollAnimation anim = new ScrollAnimation(scrollFrom, scrollTo);
            int measureWidth = getMeasuredWidth();
            if (measureWidth == 0) {
                measureWidth = Math.max(getSuggestedMinimumWidth(), 1);
            }
            anim.setDuration(Math.min(4000, absDx * 1800 / measureWidth));
            anim.setInterpolator(new LinearInterpolator());
            anim.setAnimationListener(l);
            startAnimation(anim);
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号