Android: Drag Imageview Off Screen
I am creating an Android application that programmatically creates an ImageView, to be dragged and placed anywhere on screen. I can drag the view along the screen, but when it is d
Solution 1:
The view shrinks because at some point you change the view's width/height, i.e. say getRight() - getLeft() is forced to decrease because there is not enough space on the screen.
Anyway, setting view's coordinates directly is not something you should do. Instead implement your custom ViewGroup/layout:
- Override
onLayout() - Iterate through children: use your custom logic to determine top and left coordinate for each child. In your case it would be using touch events to calculate the coordinates during dragging. For the right and bottom coordinates you can add the measured width/height of the child.
- On each child call
child.layout(left, top, right, bottom)
For an example see the code of FrameLayout at line 513 and the docs for onLayout().
Post a Comment for "Android: Drag Imageview Off Screen"