How to work with the X,Y Coordinates in android
<p>I am new to android and I am trying with positioning my drawings at the right coordinate using touch screen. When i touch the screen I obtain the coordinates(x,y) but when i press my button to draw the circle it draws the circle at a location below the point i touched.I am using a relativeLyout as my layout, and i gave it an ID as "Layout" which I use to reference it in my java class.I thought it is because i am using the addView to draw on the same layout.I tried all my best to correct it but could not. (THE CIRCLE IS DRAWN AFTER CLICKING THE BUTTON BUT NOT AT THE POSITION I WANT IT, IT GOES BELOW THE POINT I TOUCHED)Can someone please help me.
Here is my code.</p>

<pre><code>public class MyView extends View{

        float x ;
    float y ;
    int radius = 20;

    public MyView(Context context, float x, float y){

        super(context);
        this.x = x;
        this.y = y;


    }   //end constructor


    public void onDraw(Canvas canvas){
        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        paint.setAntiAlias(true);

        canvas.drawCircle(x, y, radius, paint);

    }   //end onDraw


}   //end class MyView
</code></pre>

<p>Here is my  MAIN CLASS:</p>

<pre><code>public class ButtonClickActivity extends Activity implements OnClickListener{

    RelativeLayout laying;
    Button button;
    MyView myView;

    private static float x=100;
    private static float y=100;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_click);

        laying = (RelativeLayout) findViewById(R.id.layout);
        button = (Button) findViewById(R.id.circle);


        //set listeners
        button.setOnClickListener(this);



    }   //end onCreate

    public void onClick(View view){
        switch(view.getId()){
        case R.id.circle:

        myView = new MyView(this, x, y);
        laying.addView(myView);}
</code></pre>

<p>Here is the Touch event</p>

<pre><code>public boolean onTouchEvent(MotionEvent event){

        int action = event.getAction();

        //get the type of action
        switch(action){

        case MotionEvent.ACTION_DOWN:   //you have touch the screen
            x =  event.getX();
            y =  event.getY();
                       break
                 }
}
</code></pre>

<p>Here is the Layout</p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:id="@+id/layout" &gt;

    &lt;Button 
        android:id="@+id/circle" 
        android:layout_alignParentBottom="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight = "1"
        android:text="Circle"/&gt;
&lt;/RelativeLayout&gt;
</code></pre>
