Question

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

Était-ce utile?

La solution

you should override computeScroll() for things like that and not onDraw()

Autres conseils

You can override onFinishInflate () method in your custom View class and you can write OverScroll related code under this method instead of onDraw(). For more detail click here.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top