2012-10-05 72 views
0

我有一個補間動畫在Android的問題,我嘗試從屏幕中心移動一個ImageView項目到屏幕頂部,但在變換結束後ImageView返回到第一個位置!我使用此代碼:Android:補間動畫:移動ImageView

<?xml version="1.0" encoding="utf-8"?> 
     <translate 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:interpolator="@android:anim/bounce_interpolator" 
     android:fromYDelta="0%" 
     android:toYDelta="-1500%" 
     android:duration="3000" 
     android:startOffset="3000"> 
     </translate> 

private void RunAnimations() { 

    Animation animation = AnimationUtils.loadAnimation(this, R.anim.move_up_maxname); 
    animation.reset(); 
    ImageView maxName = (ImageView) findViewById(R.id.imageView1); 
    maxName.clearAnimation(); 
    maxName.startAnimation(animation); 
} 

任何人都可以幫助我嗎?
謝謝

回答

3

你需要看看setFillAfter:

如果fillAfter是真實的,改造這個動畫執行它完成時將持續存在。

2

使用AnimationListener並在onAnimationEnd()更改ImageView(最後一點)的位置。

animation.setAnimationListener(new AnimationListener() { 

    public void onAnimationStart(Animation anim) 
    {}; 

    public void onAnimationRepeat(Animation anim) 
    {}; 

    public void onAnimationEnd(Animation anim) 
    { 
    //Change imageview position using LayoutParameters 
    }; 
});      
2

add line animation.setFillAfter(true);