Animate a view in a circle in Android

Move ImageView around the circle with animation

public void moveImageInCircle(){

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);


ValueAnimator animator = ValueAnimator.ofFloat(0, pm.getLength());

final float[] pos = new float[2];
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {

float v = (float) animation.getAnimatedValue();


pm.getPosTan(v, pos, null);

imageView.setTranslationX(pos[0]);
imageView.setTranslationY(pos[1]);
}
});

animator.setDuration(3000);
animator.setRepeatMode(ValueAnimator.RESTART);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setInterpolator(new LinearInterpolator());
animator.start();
}

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store