2
 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

3 Answers 3

2

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); } } 
Sign up to request clarification or add additional context in comments.

1 Comment

Please declare the myImageView I cant find it out how it declares lol
0

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.

2 Comments

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.
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.
0
 @Override public boolean onTouchEvent(MotionEvent event) { event.getX(); event.getY(); } 

1 Comment

can you tell me any method name. and i am using RelativeLayout. what other layout i should use to achieve this. kindly tell me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.