AndroidのObjectAnimator使用記録
2565 ワード
一般的な方法:
注意:最後のパラメータは可変パラメータで、1つの値のみが渡されると、2番目のパラメータに対応するgetメソッドが自動的に呼び出されて初期値が取得され、対応するgetメソッドがなければ、対応する変数のデフォルト値に初期値がありません.public static ObjectAnimator ofFloat(Object target, String propertyName, float... values)
public static ObjectAnimator ofInt(Object target, String propertyName, int... values)
public static ObjectAnimator ofObject(Object target, String propertyName,TypeEvaluator evaluator, Object... values)
ObjectAnimatorのプロパティをカスタマイズします.
1:オブジェクトを定義する必要があります.プロパティ:半径 radius .
2:カスタムViewは私たちのPointクラスを初期化し、onDrawで私たちのPointの半径に基づいて円を描きます.次に関数を定義します setPointRadius、この方法の「pointRadius」は私たちのObjectAnimatorの属性です.
3:ObjectAnimatorを初期化し、アニメーションを開始します.
四:私たちは addListener アニメーションステータスのリスニングを追加します.
以上がObjectAnimatorアニメーションの基本的な使い方です.
注意:最後のパラメータは可変パラメータで、1つの値のみが渡されると、2番目のパラメータに対応するgetメソッドが自動的に呼び出されて初期値が取得され、対応するgetメソッドがなければ、対応する変数のデフォルト値に初期値がありません.public static ObjectAnimator ofFloat(Object target, String propertyName, float... values)
public static ObjectAnimator ofInt(Object target, String propertyName, int... values)
public static ObjectAnimator ofObject(Object target, String propertyName,TypeEvaluator evaluator, Object... values)
:
1、 :
alpha 0~1
2、 :
rotation: Z
rotationX: X
rotationY: Y
3、 :
translationX: X
translationY: Y
4、 :
scaleX: X
scaleY: Y
ObjectAnimatorのプロパティをカスタマイズします.
1:オブジェクトを定義する必要があります.プロパティ:半径 radius .
public class Point {
private int radius;
public Point(int radius){
this.radius= radius;
}
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius= radius;
}
}
2:カスタムViewは私たちのPointクラスを初期化し、onDrawで私たちのPointの半径に基づいて円を描きます.次に関数を定義します setPointRadius、この方法の「pointRadius」は私たちのObjectAnimatorの属性です.
public class CircleView extends View {
private Point point = new Point(100);
private Paint paint = new Paint();
private int centerX = 100;
private int centerY = 100;
public CircleView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
if (mPoint != null){
paint.setAntiAlias(true);
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL);
canvas.drawCircle(centerX, centerY, point.getRadius(), paint);
}
super.onDraw(canvas);
}
/**
, set pointRadius PointRadius。
, set 。
, setPointRadius , point 。 。
,invalidate(), , 。 onDraw() 。
*/
void setPointRadius(int radius){
point.setRadius(radius);
invalidate();
}
}
3:ObjectAnimatorを初期化し、アニメーションを開始します.
ObjectAnimator animator = ObjectAnimator.ofInt(view, "pointRadius", 100, 300, 100);
animator.setDuration(2000);
animator.start();
四:私たちは addListener アニメーションステータスのリスニングを追加します.
animator.addListener(new AnimatorListenerAdapter() {
//
});
以上がObjectAnimatorアニメーションの基本的な使い方です.