HenCoder Android 自定義 View 1-6: 屬性動(dòng)畫(huà)(上手篇)
- Transition
- Animation
- View Animation
- Property Animation
- ViewPropertyAnimator
- ObjectAnimation
- ValueAnimation
ViewPropertyAnimation
view.animate().translationX(500);
ObjectAnimator
使用方式:
1.如果是自定義控件妻顶,需要添加 setter / getter 方法骤竹;
2.用 ObjectAnimator.ofXXX() 創(chuàng)建 ObjectAnimator 對(duì)象;
3.用 start() 方法執(zhí)行動(dòng)畫(huà)公荧。
public class SportsView extends View {
float progress = 0;
......
// 創(chuàng)建 getter 方法
public float getProgress() {
return progress;
}
// 創(chuàng)建 setter 方法
public void setProgress(float progress) {
this.progress = progress;
invalidate();
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
......
canvas.drawArc(arcRectF, 135, progress * 2.7f, false, paint);
......
}
}
......
// 創(chuàng)建 ObjectAnimator 對(duì)象
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "progress", 0, 65);
// 執(zhí)行動(dòng)畫(huà)
animator.setDuration(2000);
animator.setInterpolator(new AnticipateOvershootInterpolator());
animator.start();