私は、車の "直進、左折、まっすぐ、..."のような動き(訳語)と回転を行うさまざまなステップのアニメーションを作りたいと思っています。プログラムでRotateAnimationsを実行する方法の完全な例?
AnimationSet
でこれを行うことはできますが、「RELATIVE_TO_SELF」設定を使用して車の中央付近を回転すると失敗します。私はこのことについて約
Animation a = new RotateAnimation(0,90,Animation.RELATIVE_TO_SELF,0.5f,...)
を知っています。それでも回転は画面(またはキャンバス?)の左上隅の周りに発生します。
現在、私はアニメーションステップごとに手動で位置を追跡することでこれを解決していますが、これは最適ではありません。
私は私の最初のレイアウト設定が偽であることを疑う:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<!-- view that draws some background -->
<de.bsd.turtlecar.SampleView android:id="@+id/graph_view"
android:layout_height="350px"
android:layout_width="fill_parent"
android:visibility="invisible"
/>
<!-- the car -->
<ImageView android:id="@+id/car_view"
android:src="@drawable/turtle_car"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="invisible"/>
</FrameLayout>
<Button ... onClick="run" ... />
</LinearLayout>
これは、(別の場所に表示する必要があり、左上隅に車を示して - アニメーションが、後に始まる基本的にそしてそれが必要。後で移動する)。私は実行ボタンによってトリガーされた私のコードで
:ここでそう時点で
ImageView carView = (ImageView) findViewById(R.id.car_view);
print(carView);
AnimationSet animationSet = new AnimationSet(true);
TranslateAnimation a = new TranslateAnimation(
Animation.ABSOLUTE,200, Animation.ABSOLUTE,200,
Animation.ABSOLUTE,200, Animation.ABSOLUTE,200);
a.setDuration(1000);
animationSet.addAnimation(a);
RotateAnimation r = new RotateAnimation(0f, -90f,200,200); // HERE
r.setStartOffset(1000);
r.setDuration(1000);
animationSet.addAnimation(r);
...
、回転は動作しますが、私はトラックを維持する必要があります。 RELATIVE_TO_SELFを回転すると、回転は画面の(0,0)回りに発生します。
その他の質問:アニメーションが終了した後で車をスクリーンに保持するにはどうすればよいですか?
私は間違ったトラックにいるのですか?
注お使いの回転ポイントの問題を解決することがあります。最後のステップを、ここで 'carView.startAnimation(animationSet)を呼び出すことです;' – Nilzor