sajjoo
sajjoo

Reputation: 6614

change the position of a bitmap where ever i touch on screen

 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

Upvotes: 2

Views: 3499

Answers (3)

Sébastien
Sébastien

Reputation: 14821

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);
            }
        }

Upvotes: 2

krunal shah
krunal shah

Reputation: 16339

 @Override
 public boolean onTouchEvent(MotionEvent event) {
        event.getX();
        event.getY();

    }

Upvotes: 0

anon
anon

Reputation:

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.

Upvotes: 0

Related Questions