2012-06-04 46 views
0

我有一個加載屏幕,5秒鐘後關閉,然後應用程序啓動。在加載屏幕期間,我想要在背景加載屏幕圖像上運行逐幀動畫。這是一個簡單的概念,之前已被許多應用使用,我只是不知道該怎麼做,因爲我是剛剛接觸android和編程。下面是splash.java屏幕的代碼,我將代碼添加到frenchsilk.java類中,以便您可以在沒有任何其他代碼的情況下查看動畫是如何工作的。 (是的動畫已經自行運作,只有這麼遠)。Android添加幀動畫到加載屏幕

Splash.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(); 

} 

} 

Frenchsilk.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(); 
//  } 
    } 
} 

我評論過的東西拿出與*(和//實際codeing過程中),原因是其被搞亂了代碼行間距。我在想睡覺時(4800);排隊或某事可能去那裏告訴動畫開始或什麼。

回答

1

好吧,我想出了自己。只需將代碼放入受尊敬的地方,並將onWindow更改爲主java文件的底部。