2013-03-14 8 views
1

Je fais un projet androïde qui comprend une animation Frame. Mon animation fonctionne très bien dans la version 4.0, mais il ne montre pas à la section 2.2. Y at-il un moyen de le faire fonctionner en 2.2/2.3? Tout extrait de code de travail pour 2.2 serait génial.animation Frame ne fonctionne pas dans Android 2.2

peut poster mon code si nécessaire.

EDIT: Voici mon code de travail

public class FrameAnimationExample extends Activity { 
    AnimationDrawable animation; 
    @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 

      Button btnStart = (Button) findViewById(R.id.btnStart); 
      final ImageView imgView = (ImageView)findViewById(R.id.img); 

      btnStart.setOnClickListener(new View.OnClickListener() { 
      @Override 
       public void onClick(View v) { 
       startAnimation(); 
       } 
      }); 
      imgView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

     } 
     }); 
     } 

    class Starter implements Runnable { 
      public void run() { 
       animation.start(); 
      } 
     } 

     private void startAnimation(){ 
      animation = new AnimationDrawable(); 
      animation.addFrame(getResources().getDrawable(R.drawable.hud_bubble_fill_line), 100); 
      animation.addFrame(getResources().getDrawable(R.drawable.hud_bubble_fill), 100); 
      animation.addFrame(getResources().getDrawable(R.drawable.medal_brown), 100); 
      animation.addFrame(getResources().getDrawable(R.drawable.medal_silver), 100); 
      animation.addFrame(getResources().getDrawable(R.drawable.medal_gold), 100); 
      animation.setOneShot(true); 

      ImageView imageView = (ImageView) findViewById(R.id.img); 
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(80, 90); 
      params.alignWithParent = true; 
      params.addRule(RelativeLayout.CENTER_IN_PARENT);  

      imageView.setLayoutParams(params); 
      imageView.setImageDrawable(animation); 
      imageView.post(new Starter()); 
     } 
    } 
+1

Poster votre code de travail ici. – Barney

Répondre

0

u pourrait essayer

// animation call 
ImageView img = (ImageView) findViewById(R.id.img); 
img.post(animateMe); 

final Runnable animateMe = new Runnable() { 

@Override 
public void run() { 
    ImageView imageView = (ImageView) findViewById(R.id.img); 
    imageView.setBackgroundResource(R.anim.img_animation); 
    AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground(); 
    frameAnimation.start(); 
    } 
}; 

et img_animation.xml comme:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/selected" 
    android:oneshot="true"> 

<!-- ur anim images here --> 
<item android:drawable="@drawable/hud_bubble_fill_line" android:duration="100" /> 
<item android:drawable="@drawable/hud_bubble_fill" android:duration="100" /> 
<!-- and so on --> 

</animation-list> 
Questions connexes