本文介绍了帧动画未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试code的每个样品,我可以找到一个定义和运行帧动画,但ImageView的永远不会改变。在ImageView的原始图像停留。

I have tried every sample of code I can find that defines and runs a frame animation, but the ImageView never changes. The original Image in the ImageView stays.

编辑:
经过反复试验多天了,我跑我的手机,而不是在模拟器上的APK。
它的工作原理我的手机上,但由于某些原因,它没有在模拟器上。

After many days of trial and error, I ran the APK on my phone instead of the emulator.It works on my phone, but for some reason it does not on the emulator.

推荐答案

我并不很清楚为什么你不能从线程的onCreate开始动画,需要将它们贴在视图的处理程序上创建任何线程

I am not exactly clear why you can't start animations from the onCreate thread, they need to be posted to whatever thread the handler of the view was created on.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final ImageView view = (ImageView) findViewById(R.id.shell);
    view.setVisibility(ImageView.VISIBLE);
    view.setBackgroundResource(R.drawable.animation_frame);

    view.post(new Runnable(){

      public void run(){
        AnimationDrawable frameAnimation =  (AnimationDrawable) view.getBackground();
        frameAnimation.start();
      }
    });
   }
}

我不知道为什么你要做到这一点,但你做的。

I have no idea why you need to do this but you do.

编辑:这是从我的工作项目中的片段应该是你需要的一切...

edit:Here is snippets from my working project should be everything you need...

在Java的的onCreate:

in java in onCreate:

final ImageView image1 =  (ImageView) v.findViewById(R.id.coin1);
image1.post(new Runnable() {

        @Override
        public void run() {
            AnimationDrawable ani = (AnimationDrawable) image1.getBackground();
            ani.start();
        }
    });

在XML布局:

        <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/coin"
        android:id="@+id/coin1"/>

硬币的xml:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
    <item android:drawable="@drawable/coin_spin_a" android:duration="100"/>
    <item android:drawable="@drawable/coin_spin_b" android:duration="100"/>
    <item android:drawable="@drawable/coin_spin_c" android:duration="100"/>
    <item android:drawable="@drawable/coin_spin_d" android:duration="100"/>
    <item android:drawable="@drawable/coin_spin_e" android:duration="100"/>
    <item android:drawable="@drawable/coin_spin_f" android:duration="100"/>
</animation-list>

这篇关于帧动画未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 03:44