Drawing touchable layers with android
<p>I want to create a simple drawing application. I want to be able to add somme lines, circles and rectangles. And I want to select any shape and move it.
I've tried this way :<br>
    - add a view per shape, and draw the shape in the onDraw method of the view<br>
    - add each views to a relative layout  </p>

<p>I can see all the shapes, but I can only touch the first view, because it fills all the screen.
I searched in the samples an example of a "layered" app, but without success</p>

<p>Thks :)</p>

<p><strong>Edit</strong> : Code added.<br>
If I click on the rectangle, I can see the log, but if I click on the circle, there's no log.</p>

<p><strong>Edit 2</strong> : Oups, I forgot to attach the listener in the Circle... :( sorry</p>

<p>The layout :</p>

<pre><code>public class DrawingView extends RelativeLayout {

  public DrawingView(Context context) {
      super(context);
      this.setBackgroundColor(0xFFFFFFFF);
      this.addView(new Circle(context));
      this.addView(new Rectangle(context));
  }
}
</code></pre>

<p>The Circle :</p>

<pre><code>public class Circle extends View implements View.OnTouchListener {

    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    public Circle(Context context) {
        super(context);
        this.paint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        this.setMeasuredDimension(100, 100);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(50, 50, 50, this.paint);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Log.d("myApp", "cercle");
        return false;
    }

}
</code></pre>

<p>And the rectangle :</p>

<pre><code>public class Rectangle extends View implements View.OnTouchListener {

    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);


    public Rectangle(Context context) {
        super(context);
        this.paint.setStyle(Paint.Style.STROKE);
        this.setOnTouchListener(this);
        this.setX(50);
        this.setY(50);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        this.setMeasuredDimension(100, 100);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawRect(0, 0, 100, 100, this.paint);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Log.d("myApp", "Rectangle");
        return false;
    }

}
</code></pre>
