Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. private void startAnimation () {
  2.  
  3. DisplayMetrics metrics = new DisplayMetrics();
  4. getWindowManager ().getDefaultDisplay ().getMetrics (metrics);
  5.  
  6. int width = metrics.widthPixels;
  7. int height = metrics.heightPixels;
  8. float scale = metrics.density;
  9.  
  10. float initLeftX = leftBall.getX ();
  11. float initLeftY = leftBall.getY ();
  12. float targetLeftX = (width / 2) - 10;
  13. float targetLeftY = (height - outerContainer.getHeight ()) / 2 - 10;
  14.  
  15. float initRightX = rightBall.getX ();
  16. float initRightY = rightBall.getY ();
  17. float targetRightX = (width / 2) - 10;
  18. float targetRightY = (height - outerContainer.getHeight ()) / 2 - 10;
  19.  
  20. AnimatorSet animSet = new AnimatorSet ();
  21.  
  22. ObjectAnimator anim1 = ObjectAnimator.ofFloat (leftBall, "x", initLeftX, targetLeftX);
  23. ObjectAnimator anim2 = ObjectAnimator.ofFloat (leftBall, "y", initLeftY, targetLeftY);
  24. ObjectAnimator anim3 = ObjectAnimator.ofFloat (rightBall, "x", initRightX, targetRightX);
  25. ObjectAnimator anim4 = ObjectAnimator.ofFloat (rightBall, "y", initRightY, targetRightY);
  26.  
  27. animSet.play (anim1).with (anim2).with (anim3).with (anim4);
  28.  
  29. animSet.setDuration (5000);
  30. animSet.start ();
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement