如题。具体的问题:我给动画对象加载了10张图片(图片都不相同),使用该动画时通过AnimationDrawable的函数getNumberOfFrames()可以取得动画的帧数为10,将这个动画start后,通过AnimationDrawable的函数getCurrent()可以获得当前图片的引用,通过取得的图片对象的哈希码得知:显示该动画时就只停留在第一帧上不动了。谁遇到或知道怎么解决,请指教。

解决方案 »

  1.   

    今天的速度怎么~~~~(>_<)~~~~ ...
      

  2.   


    <Button android:id="@+id/framebyframe" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Frame By Frame">
    </Button>
    <ImageView android:id="@+id/myImage" android:layout_width="140dip"
    android:layout_height="140dip">
    </ImageView>frameanimation.xml:<?xml version="1.0" encoding="utf-8"?>
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
        android:oneshot="true">
        <item android:drawable="@drawable/a" android:duration="200" />
        <item android:drawable="@drawable/b" android:duration="200" />
        <item android:drawable="@drawable/c" android:duration="200" />
        <item android:drawable="@drawable/d" android:duration="200" />
        <item android:drawable="@drawable/e" android:duration="200" />
        <item android:drawable="@drawable/f" android:duration="200" />
        <item android:drawable="@drawable/g" android:duration="200" />
        <item android:drawable="@drawable/h" android:duration="200" />
        <item android:drawable="@drawable/i" android:duration="200" />
    </animation-list>
    final ImageView myImage = (ImageView) findViewById(R.id.myImage);
    Button button = (Button) findViewById(R.id.framebyframe);
    button.setOnClickListener(new View.OnClickListener() { @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    myImage.setBackgroundResource(R.layout.frameanimation);
    AnimationDrawable frameAnimation = (AnimationDrawable) myImage
    .getBackground();
    frameAnimation.start();
    }
    });
      

  3.   


    哪位高手给了你一个范例,定义了3个组件 Button ImageView 和AnimationDrawable,然后通过监听 按钮的动作 来 start() 动画。
      

  4.   

    http://groups.google.com/group/android-developers/browse_thread/thread/4a8dfff18f0abd86?pli=1
    这个网页的内容说的是:AnimationDrawable不能在onResume()中start()的解决方法。
    其中Romain Guy 提到的解决方案是:将AnimationDrawable以setImageDrawable()加载,而不是以setBackgroundDrawable()方式加载。
    但是我试了试,不清楚是什么原因还是没有解决。
    以下是对我提出的问题的补充:
    我是在handler中调用的动画的start()方法,handler中的方法执行时在onResume()执行期间。
    如果谁遇到过这个问题或知道如何解决,请指点我一下。
    谢谢。