2013-10-09 26 views
1

我存儲在RES /動畫/ draw_circle_violet.xml動畫列表動畫列表:ANDROID - 如何清除應用於ImageView的

<?xml version="1.0" encoding="utf-8"?> 
<animation-list android:oneshot="true" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:duration="10" android:drawable="@drawable/plainimg"/> 
    <item android:duration="10" android:drawable="@drawable/circlev1"/> 
    <item android:duration="10" android:drawable="@drawable/circlev2"/> 
    <item android:duration="10" android:drawable="@drawable/circlev3"/> 
    <item android:duration="10" android:drawable="@drawable/circlev4"/> 
    <item android:duration="10" android:drawable="@drawable/circlev5"/> 
    <item android:duration="10" android:drawable="@drawable/circlev6"/> 
    <item android:duration="10" android:drawable="@drawable/circlev7"/> 
    <item android:duration="10" android:drawable="@drawable/circlev8"/> 
</animation-list> 

這個動畫應用到的ImageView:

mImageView.setBackgroundResource(R.anim.draw_circle_violet); 
     AnimationDrawable frameAnimation = (AnimationDrawable) mImageView 
       .getBackground(); 
     frameAnimation.start(); 

我點擊一個按鈕來清除應用到這個ImageView的動畫:

 mImageView.clearAnimation(); 

但動畫不能刪除。另一種方式,我試試這個:

 mImageView.setAnimation(null); 

但不成功。

Plz help。


更新:我已經試過

frameAnimation.stop(); 

但仍動畫應用到ImageView的。任何理想? 這是我source code

回答

0

試試這個:

frameAnimation.stop(); 

希望這有助於:)

+0

我試過這個,但動畫仍然適用於ImageView。任何理想?感謝您的回覆。 –

+0

我已更新源代碼。 Plz的幫助。 –

0

這是一個骯髒的方式,但工程:

setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

讓我知道如果這並沒有解決你的問題。

+0

沒有方法將setBackground()應用於ImageView。只有3種方法:應用於ImageView的setBackgroundColor(int color),setBackgroundDrawable(Drawable background),setBackgroundResource(int resid)。 Plz檢查。感謝您的回覆。 –

+0

我的糟糕的'setBackground'方法用於API 16.您可以使用'setBackgroundDrawable' – 4gus71n