2 luofei987 luofei987 于 2016.05.03 11:24 提问

请问为什么动画执行完之后不会执行loadMain方法

完整代码如下,新手,求指教.

package com.example.zhihu02;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;

public class SplashActivity extends Activity {

protected static final int LOADMAIN = 1;
protected static final int UPDATEVERSION = 2;
private ImageView iv_spalh_bg;
private long startTime;

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

    initView();
    initAnimation();
    checkVersion();
}

private void checkVersion() {
    new Thread(new Runnable() {

        @Override
        public void run() {
            long endTime = System.currentTimeMillis();
            if (endTime - startTime < 3000) {
                SystemClock.sleep(3000 - (endTime - startTime));
            }else {
                Message msg = Message.obtain();
                msg.what = LOADMAIN;
                handler.sendMessage(msg);
            }
        }
    }).start();
}

private Handler handler = new Handler() {
    public void handleMessage(android.os.Message msg) {
        switch (msg.what) {
        case LOADMAIN:
            loadMain();
            break;

// case UPDATEVERSION:
// showUpdateDialog();
// break;
default:
break;
}
};
};
private void initAnimation() {
startTime = System.currentTimeMillis();
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(3000);
scaleAnimation.setStartTime(System.currentTimeMillis());
scaleAnimation.setFillAfter(true);
iv_spalh_bg.startAnimation(scaleAnimation);
}

// protected void showUpdateDialog() {
//

// }

private void initView() {
    setContentView(R.layout.activity_splash);
    iv_spalh_bg = (ImageView) findViewById(R.id.iv_spalh_bg);
}

private void loadMain() {
    Intent intent = new Intent(SplashActivity.this,MainActivity.class);
    startActivity(intent);
    finish();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.splash, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

2个回答

CSDNXIAOD
CSDNXIAOD   2016.05.03 11:32

在main函数执行之前和执行之后执行的方法
在main函数执行之前和执行之后执行的方法
CCArmature动画播放完后执行回调函数的方法
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

sl_18500
sl_18500   2016.05.03 15:00

你在run方法里面打印下endTime - startTime看看

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!