Reputation: 27
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);
Upvotes: 0
Views: 764
Reputation: 3203
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.
Upvotes: 1