title: Android canvas - Draw a hole
body: <p>Is it possible to realize the following picture in Android with canvas?</p>
  
  <p><img src="https://i.stack.imgur.com/zg4uw.png" alt="Picture with Hole"></p>
  
  <p>I want to have a hole and not only a Circle over the red layer which is yellow colored. I tried this (and failed) with the following Code in my <code>onDraw()</code>-Method:</p>
  
  <pre><code>canvas.drawBitmap(yellow, 0, 0, paint);
  canvas.drawBitmap(red, 0, 200, paint);
  Paint p = new Paint();
  p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
  canvas.drawCircle(300, 300, radius, p);
  </code></pre>
  
  <p>But when I use this code, it makes a hole through both bitmap's. At the end, this App should be a Maze with a ball, holes and other stuff. When the ball would fall into a hole it should appear under the red-Bitmap. Is it possible to realize this?</p>
  
  <p><strong>Answer:</strong></p>
  
  <p>If someone should have the same problem: use <strong>View</strong> and not SurfaceView. That was my fault, because the bg of a SurfaceView could not be set transparent. </p>