2012-06-21 7 views
3

J'ai suivi le site de développement android pour ajouter une image gif dans mon application. Mais l'image n'est pas montrée comme animée, elle se montre comme une image normale.comment ajouter l'image gif dans imageview dans android?

Animation drawable

<?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/los01" android:duration="50" /> 
<item android:drawable="@drawable/los02" android:duration="50" /> 
</animation-list> 

codage

layout.setBackgroundResource(R.drawable.bg); 
       img.setBackgroundResource(R.drawable.mylosanim); 
       AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); 
       frameAnimation.start(); 
       tv1.setText("Sorry!!!Play Again!!!"); 
       tv3.setText("Your Level-1 Score:"+Integer.toString(score)); 
       layout.setClickable(true); 
       frameAnimation.stop(); 

Répondre

1

essayer comme

AnimationDrawable frameAnimation = (AnimationDrawable)img.getBackground(); 
     if (frameAnimation.isRunning()){ 
      frameAnimation.stop(); 
     }else{ 
      frameAnimation.stop(); 
      frameAnimation.start(); 

       tv1.setText("Sorry!!!Play Again!!!"); 
       tv3.setText("Your Level-1 Score:"+Integer.toString(score)); 
       layout.setClickable(true); 
     }