Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final View target = findViewById(R.id.target);
- // Create path you would like your view to follow
- Path p = new Path();
- RectF circle = new RectF(0, 0, 400f, 400f);
- p.arcTo(circle, 0, 180);
- p.arcTo(circle, 180, 180);
- final PathMeasure pm = new PathMeasure(p, false);
- // Animating from 0 to our path length
- ValueAnimator animator = ValueAnimator.ofFloat(0, pm.getLength());
- // This will hold current position
- final float[] pos = new float[2];
- animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
- @Override
- public void onAnimationUpdate(ValueAnimator animation) {
- // Getting current length on the path
- float v = (float) animation.getAnimatedValue();
- // Getting current position..
- pm.getPosTan(v, pos, null);
- // ..and applying it
- target.setTranslationX(pos[0]);
- target.setTranslationY(pos[1]);
- }
- });
- animator.setDuration(3000);
- animator.setRepeatMode(ValueAnimator.RESTART);
- animator.setRepeatCount(ValueAnimator.INFINITE);
- animator.setInterpolator(new LinearInterpolator());
- animator.start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement