문제

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()

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top