Androidのアニメーションの最初のフレームがImageViewの上で早すぎる適用されます

StackOverflow https://stackoverflow.com/questions/4616660

質問

私は私の活動の一つで、次のビューを設定している。

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/photoLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/photoImageView"
android:src="@drawable/backyardPhoto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:scaleType="centerInside"
android:padding="45dip"
>
</ImageView>
</LinearLayout>

アニメーションセット、このディスプレイだけで罰金なし。しかし、私は非常に単純なアニメーションを表示します。だから私の活動のONSTARTオーバーライドで、私は以下のものを持っています:

@Override
public void onStart() {
 super.onStart();

    mPhotoImageView = (ImageView) findViewById(R.id.photoImageView);

 float offset = -25;
 int top = mPhotoImageView.getTop();

 TranslateAnimation anim1 = new TranslateAnimation(
Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, top, Animation.ABSOLUTE, offset);
 anim1.setInterpolator(new AnticipateInterpolator());
    anim1.setDuration(1500);
    anim1.setStartOffset(5000);

    TranslateAnimation anim2 = new TranslateAnimation(
      Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0,
      Animation.ABSOLUTE, offset, Animation.ABSOLUTE, top);
 anim2.setInterpolator(new BounceInterpolator());
    anim2.setDuration(3500);
    anim2.setStartOffset(6500);

    mBouncingAnimation = new AnimationSet(false);
    mBouncingAnimation.addAnimation(anim1);
    mBouncingAnimation.addAnimation(anim2);

    mPhotoImageView.setAnimation(mBouncingAnimation);
}

は問題があることを初めてアクティビティが表示され、写真の最初の位置の周りパディング有りの画面の中央にないとき。アニメーションの最初のフレームがすでにロードされているように思えます。アニメーションが完了した後にのみ、photoImageViewが意図した場所に背を「スナップ」します。

私が見て、見て、この問題を回避する方法を見つけることができませんでしたしました。私はphotoImageViewが画面の中央に開始し、その後、アニメーションが発生し、画面の中央に戻したいです。アニメーションは、ユーザからの対話なしに自身で起こるはずます。

役に立ちましたか?

解決

onCreate()で0を返します。

mPhotoImageView.getTop()は、最初のレイアウト/ドローはあなたのビューの正しい位置を取得するために起こった後まで待つ必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top