tags:

views:

286

answers:

1

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  A: 

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

RickNotFred
Uf... I'm really blind when I missed that overload. So am I getting this right:-I can post multiple regions in for(Rect r : regions) and it will only draw that parts no matter if I refresh everything in onDraw (tried it right now and it seems it works that way)?-There is no such thing as to put one LinearLayout over other; put background image on bottom one, invalidate top that has transparent background and see that things magically work out (Android invalidates right regions for me)?
kape123
Also, one more thing, if you know. Suppose I have 320x480 screen. I call canvas.drawBitmap with image that's 600x800. Will that bigger image draw in same time as if I crop it's top-left 320x480 part (in Photoshop) before compiling?Thanks for your help!
kape123
Actually, I'm new to this as well, but trying to come up to speed as fast as I can. I'm mostly answering based on what I've been reading. You can put Drawables on multiple layers, though and manage them with LayerDrawable. If it were me, I think I would start there.
RickNotFred
OK, thanks for your help!
kape123