protected void circleAnimator(View v) {
width = rel.getWidth();
height = rel.getHeight();
final int R = width / 3;
ValueAnimator tValue = ValueAnimator.ofFloat(0,
(float) (2.0f * Math.PI));
tValue.setDuration(1000);
tValue.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
// 圆的参数方程 x = R * sin(t) y = R * cos(t)
float t = (Float) animation.getAnimatedValue();
int x = (int) (R * Math.sin(t) + width / 2);
int y = (int) (R * Math.cos(t) + height / 2);
moveView(v, x, y);
}
});
tValue.setInterpolator(new DecelerateInterpolator());
tValue.setRepeatCount(1);
tValue.start();
}
private void moveView(View view, int x, int y) {
int left = x - view.getWidth() / 2;
int top = y - view.getHeight();
int width = left + view.getWidth();
int height = top + view.getHeight();
view.layout(left, top, width, height);
}