Android animation frame by frame
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.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
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();
}
});
}
} |