Moving the image according to the Button click
<p>I used four buttons (Up,down,Left,Right) and also i have image. I have to move the image accordingly when i press UP button i should move image in upward direction and when i press left similarly remaining both direction it should move image in left direction.I have used onclick listener and then i am trying to move image using X,Y co-ordinates.I don't how take X,Y co-ordinates.</p>

<p><strong>Here is the code.</strong> </p>

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

    Button up,left,right,down; 

         ImageView i1;

    protected void onCreate(Bundle savedInstanceState) {

                 super.onCreate(savedInstanceState);

                setContentView(R.layout.activity_main);

            up=(Button)findViewById(R.id.button1);

            left=(Button)findViewById(R.id.button2);

            right=(Button)findViewById(R.id.button3);

            down=(Button)findViewById(R.id.button4);

            i1=(ImageView)findViewById(R.id.imageView1);

            up.setOnClickListener(this);
     }

        public void onClick(View arg0) {

    Toast.makeText(getApplication(),"UP",5000).show();  

        RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) 

        i1.getLayoutParams();

        int x = (int)getRawx();

        int y = (int)getRawY();

        mParams.leftMargin = x-50;

        mParams.topMargin = y-50;

       i1.setLayoutParams(mParams);


    }

}
</code></pre>
