2015-12-15 146 views
2

我已經創建了一個AnimationDrawable,我想重複動畫無限數量和停止按鈕點擊該動畫,我分享我的代碼重複AnimationDrawable和停止按鈕點擊

anim.xml在我的佈局文件

<ImageView 
    android:id="@+id/imageViewAnimation" 
    android:layout_width="wrap_content" 
    android:layout_height="30dp" 
    android:padding="3dp" 
    android:layout_marginBottom="10dp" 
    android:layout_weight="2" 
    android:background="@color/colorOrange" 
    android:src="@drawable/anim" /> 

,並在我的活動文件

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="true" > 
    <item android:drawable="@drawable/download_anim1" android:duration="100" /> 
    <item android:drawable="@drawable/download_anim2" android:duration="100" /> 
    <item android:drawable="@drawable/download_anim3" android:duration="100" /> 
    <item android:drawable="@drawable/download_anim4" android:duration="100" /> 
    <item android:drawable="@drawable/download_anim5" android:duration="100" /> 
</animation-list> 

在那裏我已經開始我的動畫

ImageView imageViewAnimationr = (ImageView) headerView.findViewById(R.id.imageViewHeaderDownloadAnimation); 
AnimationDrawable animationDrawable = (AnimationDrawable) imageViewAnimationr.getDrawable(); 
animationDrawable.start(); 

回答

2

我剛剛發現setOneShot用於重複動畫並找到Stop在任何情況下停止動畫。

1

你可以改變oneshot=false爲重複無限次,並停止在任何情況下,你可以使用animationDrawable.stop() 喜歡它: -

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="false"> 
    <item android:drawable="@drawable/img_one" android:duration="200" /> 
    <item android:drawable="@drawable/img_two" android:duration="200" /> 
    <item android:drawable="@drawable/img_three" android:duration="200" /> 
</animation-list>