hi I'm working with the animations, I currently have 4 directional buttons, depending on which button I press, the image will move in that direction. My problem is so that the image goes beyond the edges of the screen, and I have no idea how to do it xD. For the animation use this ObjectAnimator objectAnimator= ObjectAnimator.ofFloat(IMG3, "translationX", Position_Start,Position_End);
Asked
Active
Viewed 485 times
0

Keyren
- 27
- 1
- 6
1 Answers
1
Of course! All you need to do is get the size of the screen in pixels (see here). the top left corner of the screen will be (0,0) and the bottom right will be your output from one of the functions provided.
Then, all you need to do is get the position of your view (animation) using View.getLocationOnScreen()
and/or getLocationInWindow()
to get the top left corner and using View.getWidth()
and View.getHeight()
to get the size of your view.
The final step is to make sure that View.getLocationOnScreen()
is never less than (0,0) and View.getLocationOnScreen() + (getWidth(),getHeight())
is always less than display.getSize(size)
, or whatever method you use to get screen size.
-
thank you, but I have some problems do not realize it,proceed in this way: int values [] = new int [2]; `IMGView.getLocationInWindow (values); IMGView.getWidth (); IMGView.getHeight ();` I declare these values, but I do not know how to control =( if i use `IMGView.getLocationInWindow (values)` in a if clicle give me a error,could you do me a small example? – Keyren May 23 '13 at 14:12
-
Check these posts: http://stackoverflow.com/questions/2638342/incorrect-coordinates-from-getlocationonscreen-getlocationinwindow , http://stackoverflow.com/questions/3581753/cant-figure-out-how-to-get-view-layout-width-height , http://stackoverflow.com/a/15882307/2066079, – dberm22 May 23 '13 at 14:20