Hi. I have been trying to place a view in an arbitrary location.
My aim: To overlay some rectangle of a JPG/PNG, given coordinates that relate to the JPG/PNG, with some other view, say, Gallery, or some video.
I don't want to use AbsoluteLayout, as it is depricated.
Therefore, I am using RelativeLayout, defining a dummy textbox as a placeholder, and putting my view RIGHT_TO and BELOW the textbox.
+--------+
|TextView|
| | (x,y)
+--------+-----------------------+
| |
| My View |
| |
+-----------------------+
My question is: Is there a more robust and elegant way to do that?
The problem with the way suggested above, is that it's very fragile: The coordinates need to be recalculated for every new screen. My view overlays something below. It needs to be accurately placed, which is pretty difficult to do.
- I will need to layout the screen again whenever rotated or zoomed or whatever. Worse:
- On init time, the typical time for placing the images, the coordinates of the screen are not valid. The coordinates are valid after placing the entities on screen. In order to place the entities on screen accurately, we need coordinates. Chicken and egg problem :(
- On rotation, the coordinates include the margins rather than the width of the view itself (example: on a portrait AVD, display a portrait ImageView, then press CTRL+F12 to rotate. The left, right, top and bottom of the ImageView are totally not as expected).
- When Scale-Animating, coordinates are scaled.
So I would like to find a better way to do that.
Thanks
M.