android rectF warning

android, draw, rect

Solution

It's just what it says: doing a `new RectF` inside `onDraw` creates an object every time anything is drawn. This can be a lot of objects. Just use a single `RectF`:

RectF mRect = new RectF();

protected void onDraw(Canvas canvas) {
    mRect.set(-r, -r, r, r);
    canvas.drawOval(mRect, mPaint);
}

Just to be clear: your original code is logically correct. This is just a performance improvement (albeit an important one).

Problem

I draw an oval on a canvas: ``` RectF f = new RectF(-r, -r, r, r); canvas.drawOval(f , mPaint); ``` Why I see warning on RectF? Avoid object allocations during draw/layout operations (preallocate and reuse instead)

Original source