找回密码
 注册
搜索
查看: 1458|回复: 2

[讨论] 求AnimationDrawable中isRunning用法

[复制链接]
发表于 2012-6-26 14:51:41 | 显示全部楼层 |阅读模式
本想在程序运行时自动播放动画然后跳转到菜单界面的,但是动画播放是否完成无法判断,调用了AnimationDrawable中isRunning,数据不会更新,

望高手指导下,具体代码如下:
package com.takko.iTakko.iTakko.animation;

import com.takko.iTakko.iTakko.R;
import com.takko.iTakko.iTakko.mainMenu.MainMenu;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
import android.os.Message;

public class ItakkoAppStart extends Activity{
        AnimationDrawable manimation;
        private ImageView mImageView;
        private boolean is_animation_run;
        private Handler mHandler;
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
               
                mImageView = (ImageView) findViewById(R.id.imageView1);   
                mImageView.setBackgroundResource(R.anim.appstart_animation);
                manimation = (AnimationDrawable) mImageView.getBackground();
                manimation.setOneShot(true);
                mImageView.post(new Runnable() {
                        public void run() {
                                // TODO Auto-generated method stub
                                manimation.start();
                                is_animation_run =true;
                                Message message = new Message();
                                message.what = 0;
                                mHandler.sendMessage(message);
                                }
                        });
                mHandler = new Handler(){
                        public void handleMessage(Message msg){
                                switch (msg.what) {
                                case 0:
                                        new Thread(){
                                                public void run(){
                                                        while(is_animation_run){
                                                                if(!manimation.isRunning()&&!(manimation==null)){
                                                                        Intent it = new Intent();
                                                                        it.setClass(ItakkoAppStart.this, MainMenu.class);
                                                                        startActivity(it);
                                                                        manimation.stop();
                                                                        ItakkoAppStart.this.finish();
                                                                        is_animation_run = false;
                                                                        }
                                                                }
                                                        }
                                                }.start();
                                                break;
                                                }
                                }
                        };
                        }
}[em03][em03]
发表于 2012-6-26 21:16:59 | 显示全部楼层
我没有做过安卓,做非智机出身的,看了代码,知道你的问题出在哪了.
你这样做:
new一个接口Icb,AnimationDrawable manimation后,立马 manimation.setCallback(Icb);
怎么方便怎么做,你自己看下AnimationDrawable.java和 Drawable.java就明白drawwable实现动画的原理了,
接口如下,注意第一方法也要实现,我估计你不实现的话,可能没法更新了,一直停在第一帧

public static interface Callback {
        /**
         * Called when the drawable needs to be redrawn.  A view at this point
         * should invalidate itself (or at least the part of itself where the
         * drawable appears).
         *
         * @param who The drawable that is requesting the update.
         */
        public void invalidateDrawable(Drawable who);

        /**
         * A Drawable can call this to schedule the next frame of its
         * animation.  An implementation can generally simply call
         * {@link android.os.Handler#postAtTime(Runnable, Object, long)} with
         * the parameters <var>(what, who, when)</var> to perform the
         * scheduling.
         *
         * @param who The drawable being scheduled.
         * @param what The action to execute.
         * @param when The time (in milliseconds) to run.  The timebase is
         *             {@link android.os.SystemClock#uptimeMillis}
         */
        public void scheduleDrawable(Drawable who, Runnable what, long when);

        /**
         * A Drawable can call this to unschedule an action previously
         * scheduled with {@link #scheduleDrawable}.  An implementation can
         * generally simply call
         * {@link android.os.Handler#removeCallbacks(Runnable, Object)} with
         * the parameters <var>(what, who)</var> to unschedule the drawable.
         *
         * @param who The drawable being unscheduled.
         * @param what The action being unscheduled.
         */
        public void unscheduleDrawable(Drawable who, Runnable what);
    }
点评回复

使用道具 举报

 楼主| 发表于 2012-6-26 15:56:00 | 显示全部楼层
没人回应吗?自己先顶一个[em03]
点评回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-5-17 22:55 , Processed in 0.048161 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表