andriod一个不错的启动菜单显示屏动画效果

27 阅读1分钟

android:id="@+id/SplashImageView"

android:layout_gravity="center"




3 点启动窗口动画效果后显示的main.xml



<LinearLayout xmlns:android="schemas.android.com/apk/res/and…"

android:orientation\="vertical" 

android:layout\_width\="fill\_parent" 

android:layout\_height\="fill\_parent" 

/> 

<TextView

android:layout\_width\="fill\_parent" 

android:layout\_height\="wrap\_content" 

android:text\="@string/hello" 

/> 



4 SplashScreen.java



这里是欢迎启动类的核心部分



public class SplashScreen extends Activity {

/**

 \* The thread to process splash screen events 

 \*/ 

private Thread mSplashThread;    

 /\*\* Called when the activity is first created. \*/ 

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);    // Splash screen view 

setContentView(R.layout.splash);     

    // Start animating the image 

final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView); 

splashImageView.setBackgroundResource(R.drawable.flag); 

final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground(); 

splashImageView.post(new Runnable(){ public void run() { 

    frameAnimation.start();

}

 }); 

final SplashScreen sPlashScreen = this;   



// The thread to wait for splash screen events 

mSplashThread =  new Thread(){ 

@Override 

public void run(){ 

try { 

synchronized(this){ 

// Wait given period of time or exit on touch 

wait(5000); 

} 

} 

catch(InterruptedException ex){    

}finish();     

// Run next activity 

Intent intent = new Intent(); 

intent.setClass(sPlashScreen, MainActivity.class); 

startActivity(intent); 

stop();     

 } 

}; 

 mSplashThread.start(); 

}@Override

public boolean onCreateOptionsMenu(Menu menu){

super.onCreateOptionsMenu(menu);

return false;

}

/\*\* 

 \* Processes splash screen touch events 

 \*/ 

@Override 

public boolean onTouchEvent(MotionEvent evt) 

{ 

if(evt.getAction() == MotionEvent.ACTION\_DOWN) 

{ 

synchronized(mSplashThread){ 

mSplashThread.notifyAll(); 

} 

} 

return true; 

} 

4 为了更好看,在values 目录下添加样式文件

styles.xml:

<style name="Animations.SplashScreen"> <item name="android:windowEnterAnimation">@anim/appear</item> <item name="android:windowExitAnimation">@anim/disappear</item>