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>

ギャラクシーノートで問題が発生します。誰かアイデアがあれば助けてください。よろしくお願いします。

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 に答える