I created a custom view by expanding the View.
public class CustomView extends View { private Canvas canvas2; private Bitmap backingBitmap;
In the CustomView constructor, I have the following code:
backingBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); canvas2 = new Canvas(backingBitmap);
In onDraw, I have:
protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(100, 100, 50, paint); canvas2.drawCircle(0, 0, 10, paint); }
I see a circle that is drawn using the canvas object, but not one that is drawn using the canvas2 object. My understanding is that you only need to create a mutable Bitmap and make it a Canvas bitmap. Can someone point out what is wrong here?
Bonus question: where is the custom canvas object created on the screen, and how to set its position?
Reason for creating multiple canvases: I have a SurfaceView that spans the entire screen. Thus, basically his canvas covers the entire screen. I need to make a rectangle that looks like a window on the screen, and all that is needed is to animate within this window. Basically, if you transfer an image to this window, the image should not be drawn outside the borders of the window.
Hooray!
source share