0

in the onDraw(Canvas canvas1) method i see how it is possible to draw shapes using the passed argument of "canvas1". However, if i were to create a new Canvas object example":

Canvas canvas2 = new Canvas();
Paint paint = new Paint();
paint.setColor(Color.BLUE);

canvas2.drawRect(55,87,130,600, paint);

canvas2 won't be displayed on screen, how can i get it displayed together with the canvas1 object?

Mark Manickaraj
  • 1,661
  • 5
  • 28
  • 44

3 Answers3

0

When you create canvas using Canvas() constructor, your get an empty raster canvas. As per documentation:

Construct an empty raster canvas. Use setBitmap() to specify a bitmap to draw into.

This means that your drawings are just thrown away unless you explicitly attach bitmap to Canvas object.

inazaruk
  • 74,247
  • 24
  • 188
  • 156
0

Are you trying to draw layers? Perhaps you need to use a viewgroup such as FrameLayout with two children views: one using canvas1, the other using canvas2.

f20k
  • 3,106
  • 3
  • 23
  • 32
0

I'm using custom ImageViews rendered in a FrameLayout as I explained in this thread.

Community
  • 1
  • 1
Narcís Calvet
  • 7,304
  • 5
  • 27
  • 47