2011-01-06 11 views
1

に適用され、私は私の活動の一つで、次のビューを設定していますandroid:src="@drawable/backyardPhoto"アニメーションセットなし
Androidのアニメーションの最初のフレームが早すぎるImageViewの

</ImageView>
</LinearLayout>
>
android:scaleType="centerInside"
android:padding="45dip"
android:gravity="center"
android:layout_width="fill_parent"
、これはうまく表示されます。しかし、私は非常に単純なアニメーションを表示したい。だから私の活動の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を画面の中央で開始し、アニメーションを実行して画面の中央に戻したいと思います。アニメーションは、ユーザーとのやりとりなしに単独で発生する必要があります。

答えて

0

mPhotoImageView.getTop()はonCreate()で0を返します。最初のレイアウト/描画が起こってからViewの正しい位置が得られるまで待つ必要があります。

+0

ありがとうRomain Guy!これで解決しました。 – Robert

関連する問題