0
votes

Quick question - I'm having control that's extending LinearLayout and I'm overriding it's onPaint method like this

@Override
protected void onDraw(Canvas canvas) {

    super.dispatchDraw(canvas);

    _background.draw(canvas);
    _object1.draw(canvas);
    _object2.draw(canvas);
    _object3.draw(canvas);

    // etc...

}

Every 40ms I invoke postInvalidate() in background and onPaint gets called on UI thread. The problem is _background.draw is taking over 80% of my drawing time.

So - is it possible to somehow cache background and not redraw it every time?

1
Why are you invalidating every 40ms? Are the objects moving across the background or are the objects themselves changing but staying in the same relative position?RickNotFred
Objects are both moving and changing (moving animation)... there are moments when they are standing, but that's special case (<10% of time)nikib3ro

1 Answers

1
votes

You can specify a region to postInvalidate() to control the area that gets redrawn.