2013-03-14 57 views
1

我正在製作一個包含框架動畫的Android項目。我的動畫在4.0中正常工作,但不在2.2中顯示。有什麼辦法可以讓它在2.2/2.3下工作嗎?任何工作代碼片段爲2.2將是很好的。框架動畫在Android 2.2中不起作用

如果需要,可以發佈我的代碼。

編輯: 這是我工作的代碼

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

發表您的工作在這裏的代碼。 – Barney 2013-03-14 08:37:34

回答

0

ü可以嘗試

// 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(); 
    } 
}; 

,並與像img_animation.xml:

<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>