ObjectAnimatorとPathを使ったアニメーション
下記のクラスを使ったアニメーションについてのメモ
*APIレベルが21と高いのが難点
| オブジェクトの属性をアニメーションする |
| 直線、曲線等の様々な線を表現する |
コード
Viewを設定した軌跡に沿って移動させるアニメーションは下記のようになる。- Pathクラスを使って、アニメーションの軌跡を設定する。
- ObjectAnimator#ofFloatでアニメーション対象プロパティ1と2をそれぞれx座標とy座標に設定し、Pathクラスを渡す。
// アニメーションのターゲット
View targetView = new View(getApplicationContext());
targetView.setLayoutParams(new LayoutParams(100, 100));
targetView.setBackgroundColor(Color.RED);
setContentView(targetView);
// アニメーションの軌跡
Path path = new Path();
// 中心座標(500,500),半径50,時計回り
path.addCircle(500, 500, 50, Direction.CW);
// アニメーションのクラス
ObjectAnimator animator = ObjectAnimator.ofFloat(targetView, "x", "y",path);
// アニメーションの実行時間
animator.setDuration(10000);
// アニメーション開始
animator.start();