I have used OverScroller for implementing scroll of my view.
Here is some code:
@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();
}
It works fine. But on device with Full HD screen (Sony xperia Z) the method onDraw calls 4 times. On "Samsung Galaxy Note 2" it calls about 10 times. Hence on xperia i see lags. What can i do to improve performance ?
UPD: Here is full code http://xsnippet.org/359714
you should override computeScroll() for things like that and not onDraw()