Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. final View target = findViewById(R.id.target);
  2.  
  3. // Create path you would like your view to follow
  4. Path p = new Path();
  5. RectF circle = new RectF(0, 0, 400f, 400f);
  6. p.arcTo(circle, 0, 180);
  7. p.arcTo(circle, 180, 180);
  8.  
  9. final PathMeasure pm = new PathMeasure(p, false);
  10.  
  11. // Animating from 0 to our path length
  12. ValueAnimator animator = ValueAnimator.ofFloat(0, pm.getLength());
  13. // This will hold current position
  14. final float[] pos = new float[2];
  15. animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  16. @Override
  17. public void onAnimationUpdate(ValueAnimator animation) {
  18. // Getting current length on the path
  19. float v = (float) animation.getAnimatedValue();
  20.  
  21. // Getting current position..
  22. pm.getPosTan(v, pos, null);
  23.  
  24. // ..and applying it
  25. target.setTranslationX(pos[0]);
  26. target.setTranslationY(pos[1]);
  27. }
  28. });
  29.  
  30. animator.setDuration(3000);
  31. animator.setRepeatMode(ValueAnimator.RESTART);
  32. animator.setRepeatCount(ValueAnimator.INFINITE);
  33. animator.setInterpolator(new LinearInterpolator());
  34. animator.start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement