【发布时间】:2013-12-02 13:01:57
【问题描述】:
我使用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
【问题讨论】:
标签: android performance android-scroll