我使用OverScroller来实现视图的滚动。
这是一些代码:
@Override
protected void onDraw(Canvas canvas) {
if (scroller.computeScrollOffset()){
int x = scroller.getCurrX();
int y = scroller.getCurrY();
scrollTo(x, y);
ViewCompat.postInvalidateOnAnimation(this);
}
super.onDraw(canvas);
}
public void open(){
scroller.startScroll(0, 0, 0, -mContent.getMeasuredHeight(), ANIMATION_TIME);
invalidate();
}
public void close(){
scroller.startScroll(0, getScrollY(), 0, mContent.getMeasuredHeight(), ANIMATION_TIME);
invalidate();
}
它工作正常。但是在具有全高清屏幕(索尼 xperia Z)的设备上,方法 onDraw 调用了 4 次。在“Samsung Galaxy Note 2”上,它调用了大约 10 次。因此在 xperia 上我看到了滞后。我能做些什么来提高性能?
UPD:这是完整的代码http://xsnippet.org/359714