Search code examples
androidandroid-layouttouch-event

Android : Move arrow's end point and start point on user's touch event


I have Relative layout with background @mipmap/arrow. I am adding this relative layout (On user touch) in another relative layout which is having ImageView (using imageRelativeLayout.addView(arrowRelativeLayout)).

Goal :

1) I want to add arrow on ImageView after onTouchEvent() to particular (x,y) position. (This is working perfectly)

2) After adding arrow, I want to move arrow's end Point or start Point as per user's touch

3) when user touch on arrow's end point then it should move to respective (x,y) position but start point should be fixed

4)when user touch on arrow's start point then it should move to resp. (x,y) position but end point should be fixed

arrow.png

Arrow Head is Start Point & Arrow tail is End Point Please Help me

Thanks in advance


Solution

  • So add some invisible views and anchor them to the start end location of the arrows, when a user presses this move them to the new location and then update the image view.

    It depends on your graphics if the arrow is edge to edge or corner to corner within the rect, i would suggest corner to corner then you just have to set the layout parameters with the correct top/left and bottom/right also Rotate / Flip it depending on your start end points, but you only need to rotate by 90,180,270 degrees.

    This method will mean that your arrow head will be squashed or stretched, if you want you can include a seperate arrow head which uses the angle generated and rotates to this angle, anchoring with the end of the arrow line that you want.