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);
}
}
}
PageScrollTab.java 文件源码
java
阅读 35
收藏 0
点赞 0
评论 0
项目:PageScrollView
作者:
评论列表
文章目录