title: Not visible overlay picture over a SurfaceView
body: <p>I'm trying to write a vintage videogame for Android devices, which "screen" is displayed through a <code>SurfaceView</code> subclass called <code>GraphicSurface</code>. I would also show on the bottom-right corner of the layout an alpha overlay of a "joypad" picture (<code>ImageView</code> subclass called <code>JoyPadView</code>) touch-events sensitive, to use as game controller. Reading around I chose the most accredited solution as follows but it doesn't work. In fact the joypad never appears although it still receive touch events.
  I guess the problem is the surfaceView drawing thread continuing to cover the joypad picture but I don't know what really happens and how to manage it.</p>
  
  <p>Here is the layout XML code:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" &gt;
  
  &lt;com.example.munchman.GraphicSurface
      android:id="@+id/graphicSurface"
      android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  
  &lt;com.example.munchman.JoyPadView
      android:id="@+id/joyPadView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom|right"
      android:alpha="0.8"
      android:src="@drawable/joypad"
      android:visibility="visible" /&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>And here's the (simplified) code of <code>SurfaceView</code> subclass:</p>
  
  <pre><code>public class GraphicSurface extends SurfaceView implements SurfaceHolder.Callback {
  
  //... class attributes  
  
  // INNER CLASS: DRAWING THREAD --------------
  class DrawingThread extends Thread {
      private boolean running = false;
  
      public synchronized void setRunning(boolean run) {
          running = run;
      }
  
      @Override
      public void run() {
          long timeInterval = 1000l / fps;
          long startTime = System.currentTimeMillis();
          long sleepTime;
          Bitmap scrBmp;
          Canvas c;
  
          while (running) {
              // DRAWING
              c = null;
              startTime = System.currentTimeMillis();
              try {
                  c = holder.lockCanvas();
                  if (c != null &amp;&amp; screen != null) {
                      synchronized (holder) {  
                          //... "screen" drawing code  
                          c.drawBitmap(scrBmp, origRect, destRect, null);
                      }               
                  }
                  else {
                      if (c == null) Log.w(TAG, "run(): lockCanvas returned null canvas");
                      else Log.w(TAG, "run(): null screen!");
                  }
              } catch (Exception e) {
                  Log.e(TAG, "run(): drawing canvas:" + Log.getStackTraceString(e) );
              } finally {
                  if (c != null) holder.unlockCanvasAndPost(c);
              }
              // SLEEP TIME
              sleepTime = timeInterval - (System.currentTimeMillis()-startTime);
              try {
                  if (sleepTime &gt; 0) sleep(sleepTime);
                  else sleep(timeInterval);
              } catch (Exception e) {
                  Log.e(TAG, "run(): sleeping: " + e);
              }               
          }
      }
  }
  
  private DrawingThread drawingThread = null;
  
  // CONSTRUCTORS -------------------
  public GraphicSurface(Context context) {    
      super(context);
      init();
  }
  
  public GraphicSurface(Context context, AttributeSet attributes) {
      super(context, attributes);
      init();
  }
  
  public GraphicSurface(Context context, AttributeSet attributes, int defStyle) {
      super(context, attributes, defStyle);
      init();
  }
  
  // CLASS METHODS -----------------
  private void init () {
  Log.d(TAG, "init()");
      holder = getHolder();
      holder.addCallback(this);
      setFocusable(true);
      drawingThread = new DrawingThread();
  drawingThread.setName(TAG);
  fps = DEFAULT_FPS;
  //... other code  
  }
  
    /** Enable the SurfaceView embedded drawing thread.
       */
      public synchronized void startDrawingThread() {
          Log.d(TAG, "startDrawingThread()");
          if (drawingThread == null) drawingThread = new DrawingThread();
          if (!drawingThread.isAlive()) {
              drawingThread.setRunning(true);
              drawingThread.start();
          }
      }
  }
  </code></pre>
  
  <p>Can anyone help me ?</p>