views:

40

answers:

3

hello guys,

 I have a large image on the screen and I want to display a small image on that image where I touch the screen. but I do not know how to change the position of the image when I touch on the screen and the small image must display where ever I touch on screen.

any suggestions or hint will be appreciative.

thanks

A: 

User first the method onTouchEvent() to get the position of your touch.

Then i suppose you have your Bitmap placed in a UIElement like for example ImageView? And if you're using AbsoluteLayout you can set the ImageView object at the same coordinates you reveiced in the ontouchEvent.

Roflcoptr
Absolute Layout is deprecated in 2.1 update 1. so i am using Relative Layout. can you point me some Method for this. i have positions aswell from ontouch event. but do not know any method to set these positions.
sajjoo
Yes it is, but if you haven't any other UI elements than your image, and if you want to place your image on absolute coordinate positions, i think it is necessary to use it.
Roflcoptr
A: 
 @Override
 public boolean onTouchEvent(MotionEvent event) {
        event.getX();
        event.getY();

    }
krunal shah
can you tell me any method name. and i am using RelativeLayout. what other layout i should use to achieve this. kindly tell me.
sajjoo
A: 

Suppose you have your moving bitmap already in an ImageView which is part of your RelativeLayout. Whenever the user touches the screen, you just have to change the position of the ImageView, by changing its margins.

You should try something like this:

         @Override
     public boolean onTouchEvent(MotionEvent event) {

            int action = event.getAction();         

            if (action == MotionEvent.ACTION_DOWN) 
            {    
            RelativeLayout.LayoutParams params = myImageView.getLayoutParams();
            params.setMargins(event.getX(),event.getY(), 0, 0);
            myImageView.setLayoutParams(params);
            }
        }
Sebastien