J'utilise une animation d'image pour afficher certaines images. Mais cela ne fonctionne que dans une action de bouton. Je veux appeler cette fonction quand le programme démarre. Comment puis-je y parvenir sans un bouton?Animation de cadre sous Android?
J'utilise le code suivant pour l'animation:
public class FrameAnimationActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.setupButton();
}
private void setupButton(){
Button b = (Button)this.findViewById(R.id.startFAButtonId);
b.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v){
parentButtonClicked(v);
}
});
}
private void parentButtonClicked(View v){
animate();
}
private void animate(){
ImageView imgView = (ImageView)findViewById(R.id.imageView);
imgView.setVisibility(ImageView.VISIBLE);
imgView.setBackgroundResource(R.drawable.frame_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) imgView.getBackground();
if (frameAnimation.isRunning()){
frameAnimation.stop();
}
else{
frameAnimation.stop();
frameAnimation.start();
}
}
}
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/colored-ball1" android:duration="50" />
<item android:drawable="@drawable/colored-ball2" android:duration="50" />
<item android:drawable="@drawable/colored-ball3" android:duration="50" />
<item android:drawable="@drawable/colored-ball4" android:duration="50" />
<item android:drawable="@drawable/colored-ball5" android:duration="50" />
<item android:drawable="@drawable/colored-ball6" android:duration="50" />
<item android:drawable="@drawable/colored-ball7" android:duration="50" />
<item android:drawable="@drawable/colored-ball8" android:duration="50" />
</animation-list>
peut-être vous devriez vérifier les démos de l'API, il vient dans les exemples de votre SDK. Avait été une grande aide pour moi quand j'étais un Noob, et même maintenant .. – Shouvik
@ Shouvik: J'ai obtenu ce code à partir de démos de l'API, mais son ne fonctionne pas à côté de l'action du bouton – Jeff