2013-10-08 77 views
0

我有一個imageview,我想動畫(只是放大它)與動畫。對於 動漫我的XML代碼:動畫沒有觸發

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="schemas.android.com/apk/res/android" 
xmlns:android1="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/linear_interpolator" > 

<scale 
    android:duration="1000" 
    android:fillBefore="true" 
    android:fromXScale="1.0" 
    android:fromYScale="1.0" 
    android:toXScale="3.0" 
    android:toYScale="3.0" /> 

</set> 

而且在我的活動:

createAnims(); 
playButton.startAnimation(animPlay1); 

凡createAnims()方法做到這一點:

animPlay1 = AnimationUtils.loadAnimation(this, R.anim.playbut_scaleup); 
animPlay1.setRepeatCount(2); 
animPlay1.start(); 

圖片中展現,但動畫不管用。 (該ImageView的被稱爲爲playButton)

+0

的xmlns:機器人沒有正確的網址。 –

回答

2

試試這個代碼,它可以幫助你...;)

public class MainActivity extends Activity { 
private ImageView mImageView; 
private Button mAnimButton; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.test3_main_activity); 

    mImageView = (ImageView) findViewById(R.id.ImageView); 
    mAnimButton = (Button) findViewById(R.id.AnimationButton); 
    mAnimButton.setOnClickListener(mClickListener); 
} 

private View.OnClickListener mClickListener = new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     mImageView.startAnimation(getAnimation()); 
    } 
}; 

private Animation getAnimation(){ 
    ScaleAnimation animation = new ScaleAnimation(1, 3, 1, 3); 
    animation.setDuration(1000); 
    animation.setRepeatCount(Animation.INFINITE); 
    animation.setRepeatMode(Animation.REVERSE); 
    return animation; 
} 
} 

試試這個XML,它會工作...

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/accelerate_interpolator" > 
<scale 
    android:duration="1000" 
    android:fromXScale="1" 
    android:fromYScale="1" 
    android:repeatCount="infinite" 
    android:repeatMode="reverse" 
    android:toXScale="3" 
    android:toYScale="3" /> 

</set> 
+0

太棒了!像魅力和我需要的確切動畫一樣工作。仍然好奇爲什麼XML動畫不起作用。 –