0

我有一个加载屏幕,它在 5 秒后关闭,然后应用程序启动。在加载屏幕期间,我希望在背景加载屏幕图像之上运行逐帧动画。这是一个简单的概念,之前已经被许多应用程序使用过,我只是不知道该怎么做,因为我是 android 新手并且一起编程。下面是 splash.java 屏幕的代码,我将把代码包含在 frenchsilk.java 类中,这样您就可以在没有任何其他代码的情况下看到动画是如何工作的。(是的,动画本身就已经开始工作了)。

飞溅.java

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Splash extends Activity {

    MediaPlayer ourSong;


@Override
protected void onCreate(Bundle PieLovesPie) {
    // TODO Auto-generated method stub
    super.onCreate(PieLovesPie);
    setContentView(R.layout.splash);
    ourSong = MediaPlayer.create(Splash.this, R.raw.sound2);
    ourSong.start();
    Thread timer = new Thread(){
        public void run(){
            try{
                      sleep(4800);

            } catch (InterruptedException e){
                e.printStackTrace();
            }finally{
    *I shortened these*     Intent open"appname" = new Intent"packageNameCode"
    *2 lines for space resonse* startActivity(open"appname");
            }
        }
    };
    timer.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    ourSong.release();
    finish();

}

}

法国丝绸.java

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;

public class FrenchSilk extends Activity {
/** Called when the activity is first created. */

AnimationDrawable mainanimation; 

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frenchsilk);

    ImageView mainimage = (ImageView) findViewById(R.id.MainAnim); 
    mainimage.setBackgroundResource(R.anim.mainanim); 
    mainanimation = (AnimationDrawable) mainimage.getBackground(); 
//        mainanimation.start();  
}
public void onWindowFocusChanged (boolean hasFocus)  
{ 
    super.onWindowFocusChanged(hasFocus); 
//        AnimationDrawable frameAnimation = (AnimationDrawable) mainimage.getBackground(); 
//        if(hasFocus) { 
        mainanimation.start(); 
//        } else { 
//            mainanimation.stop(); 
//        } 
    } 
}

我用*注释了一些东西(和 // 在实际的编码过程中),因为它弄乱了代码行间距。我在想睡下(4800);一个类或其他东西可能会去那里告诉动画开始或其他东西的行。

4

1 回答 1

1

好的,所以我自己想通了。只需将代码放入受人尊敬的位置,并且 onWindow 在主 java 文件的底部发生了更改。

于 2012-06-04T17:12:25.913 回答