Hencoder学习笔记1-6

HenCoder Android 自定义 View 1-6: 属性动画(上手篇)

  • Transition
  • Animation
    • View Animation
    • Property Animation
      • ViewPropertyAnimator
      • ObjectAnimation
      • ValueAnimation

ViewPropertyAnimation

view.animate().translationX(500);

ObjectAnimator

使用方式:

1.如果是自定义控件,需要添加 setter / getter 方法;
2.用 ObjectAnimator.ofXXX() 创建 ObjectAnimator 对象;
3.用 start() 方法执行动画。

public class SportsView extends View {
  float progress = 0;
......
// 创建 getter 方法
public float getProgress() {
    return progress;
}
// 创建 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);
    ......
    }
}
......
// 创建 ObjectAnimator 对象
ObjectAnimator animator = ObjectAnimator.ofFloat(view,      "progress", 0, 65);
// 执行动画
animator.setDuration(2000);
animator.setInterpolator(new AnticipateOvershootInterpolator());
animator.start();
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容