Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void startAnimation () {
- DisplayMetrics metrics = new DisplayMetrics();
- getWindowManager ().getDefaultDisplay ().getMetrics (metrics);
- int width = metrics.widthPixels;
- int height = metrics.heightPixels;
- float scale = metrics.density;
- float initLeftX = leftBall.getX ();
- float initLeftY = leftBall.getY ();
- float targetLeftX = (width / 2) - 10;
- float targetLeftY = (height - outerContainer.getHeight ()) / 2 - 10;
- float initRightX = rightBall.getX ();
- float initRightY = rightBall.getY ();
- float targetRightX = (width / 2) - 10;
- float targetRightY = (height - outerContainer.getHeight ()) / 2 - 10;
- AnimatorSet animSet = new AnimatorSet ();
- ObjectAnimator anim1 = ObjectAnimator.ofFloat (leftBall, "x", initLeftX, targetLeftX);
- ObjectAnimator anim2 = ObjectAnimator.ofFloat (leftBall, "y", initLeftY, targetLeftY);
- ObjectAnimator anim3 = ObjectAnimator.ofFloat (rightBall, "x", initRightX, targetRightX);
- ObjectAnimator anim4 = ObjectAnimator.ofFloat (rightBall, "y", initRightY, targetRightY);
- animSet.play (anim1).with (anim2).with (anim3).with (anim4);
- animSet.setDuration (5000);
- animSet.start ();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement