1

我做了如下

imageView = (ImageView) findViewById(R.id.animation_iv);
imageView.setImageResource(R.drawable.loadinganim);
AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getDrawable();
animationDrawable.start();

我在 loading.xml 中有复制图像

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"  
    android:oneshot="false">  
    <item android:drawable="@drawable/v1" android:duration="160" />  
    <item android:drawable="@drawable/v4" android:duration="160" />  
    <item android:drawable="@drawable/v7" android:duration="160" />  
</animation-list>

它在 Galaxy Note 中出现问题。如果有人有想法请帮助我。在此先感谢

4

2 回答 2

0

你必须这样做:

    imageView.setBackgroundResource(R.drawable.loading);
    final AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground(); 
    startAnimation(frameAnimation);

startAnimation 方法是:

  public void startAnimation(final AnimationDrawable frameAnimation){
    new Thread(new Runnable() {
        public void run(){
            // some code that runs outside the ui thread.
            frameAnimation.start();
        }
    }).start();
  }

我认为在 UI 线程以外的线程上运行动画将解决您的问题。

于 2012-07-11T09:17:30.177 回答
-1
AnimationDrawable imageAnimation;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);


    setContentView(R.layout.main);


    ImageView image = (ImageView) findViewById(R.id.test_image);
    image.setImageResource(R.drawable.loading);
    imageAnimation=(AnimationDrawable) image.getDrawable();

 }

public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    imageAnimation.start();
  }
于 2013-01-23T16:18:19.870 回答