/
Practice08ObjectAnimatorLayout.java
51 lines (41 loc) · 1.76 KB
/
Practice08ObjectAnimatorLayout.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.geekholt.practiceui.view.lesson5.practice08;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
import com.geekholt.practiceui.R;
public class Practice08ObjectAnimatorLayout extends RelativeLayout {
Practice08ObjectAnimatorView view;
Button animateBt;
public Practice08ObjectAnimatorLayout(Context context) {
super(context);
}
public Practice08ObjectAnimatorLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public Practice08ObjectAnimatorLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
view = (Practice08ObjectAnimatorView) findViewById(R.id.objectAnimatorView);
animateBt = (Button) findViewById(R.id.animateBt);
animateBt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO 在这里处理点击事件,用 ObjectAnimator 播放动画
// 1. 用 ObjectAnimator 创建 Animator 对象
// 2. 用 start() 执行动画
// *. 记得在 Practice08ObjectAnimatorView 中为 progress 添加 setter/ getter 方法!
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "progress", 60f);
animator.setDuration(1000);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.start();
}
});
}
}