Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Android] Animation frame by frame

    13 août 2012 à 13:28:05

    Bonjour, j'ai un petit soucis avec mon animation. Lorsque je définis une source pour l’ImageView dans le xml (« android:src=@drawable/stance1») elle est présente durant l’animation (image fixe doublée de l’animation )mais lorsque je ne définie pas de source l’ImageView reste vide pendant l’animation. Je ne comprends pas ou est l’erreur merci.

    public class MainActivity extends Activity {
    	
    	Button monBouton;
    	ImageView marco;
    	AnimationDrawable animation;
    	
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            monBouton = (Button)findViewById(R.id.button1);
            marco = (ImageView)findViewById(R.id.imageView1);
        	
        	int duration = 150;
        	
        	 BitmapDrawable frame1 =
        	            (BitmapDrawable)getResources().getDrawable(R.drawable.stance1);
        	        BitmapDrawable frame2 =
        	            (BitmapDrawable)getResources().getDrawable(R.drawable.stance2);
        	        BitmapDrawable frame3 =
        	            (BitmapDrawable)getResources().getDrawable(R.drawable.stance3);
        	        BitmapDrawable frame4 =
            	        (BitmapDrawable)getResources().getDrawable(R.drawable.stance4);
    
        	        animation = new AnimationDrawable();       
        	        animation.addFrame(frame1, duration);
        	        animation.addFrame(frame2, duration);
        	        animation.addFrame(frame3, duration);
        	        animation.addFrame(frame4, duration);
        	        
        	        marco.setBackgroundDrawable(animation);
        	        animation.setOneShot(false);
        
        	monBouton.setOnClickListener(new View.OnClickListener() {
    			
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				
    				animation.start();
    						
    			}
    		});   
        }
        
    }
    
    • Partager sur Facebook
    • Partager sur Twitter

    [Android] Animation frame by frame

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown