介绍一些安卓开发常用的动画效果
控件画圆的方法 ,可在搜索的动画里有所应用(放大镜查找之类的)
private void startViewAnimScale(View mView) {
x0 = mView.getX();
y0 = mView.getY();
final int radius = mView.getWidth() / 9;
mAnimator = ValueAnimator.ofFloat(0, 360);
mAnimator.setDuration(1000);
mAnimator.setRepeatCount(-1);
mAnimator.setInterpolator(null);
mAnimator.start();
mAnimator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float gress = (Float) animation.getAnimatedValue();
float x1 = (float) (x0 + radius * Math.cos(gress * 3.141592654 / 180));
float y1 = (float) (y0 + radius * Math.sin(gress * 3.141592654 / 180));
mView.setX(x1);
mView.setY(y1);
mView.invalidate();
}
});
}
无限循环抖动的动画,用来吸引别人注意
public static AnimatorSet rota(View view) {
ObjectAnimator items = ObjectAnimator.ofFloat(view, "rotationX", 0, 20, 0);
ObjectAnimator items1 = ObjectAnimator.ofFloat(view, "rotationY", 0, 20, 0);
ObjectAnimator items2 = ObjectAnimator.ofFloat(view, "rotation", 0, 20, 0);
items.setRepeatCount(5);
items1.setRepeatCount(5);
items2.setRepeatCount(5);
final AnimatorSet set = new AnimatorSet();
set.playTogether(items, items1, items2);
set.setInterpolator(new AnticipateOvershootInterpolator());
set.setDuration(150);
set.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator animation) {
new Handler().postDelayed(new Runnable() {
public void run() {
set.start();
}
}, 2000);
}
@Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
return set;
}