经常可以看到很多得Android程序都会有一个启动动画效果,这样可以使得用户在程序启动中不觉的烦躁,这一点尤其适用于启动时间比较长的程序。
下面贴一个这种Android效果的主要实现代码,希望对大家有帮助。
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
package
com.pxr.tutorials.splash
;
import android.app.Activity ; import android.content.Intent ; import android.os.Bundle ; import android.view.MotionEvent ; public class SplashScreen extends Activity { protected int _splashTime = 10000 ; private Thread splashTread ; /** Called when the activity is first created. */ @Override public void onCreate (Bundle savedInstanceState ) { super. onCreate (savedInstanceState ) ; setContentView (R. layout. splash ) ; final SplashScreen sPlashScreen = this ; // thread for displaying the SplashScreen splashTread = new Thread ( ) { @Override public void run ( ) { try { synchronized ( this ) { wait (_splashTime ) ; } } catch ( InterruptedException e ) { } finally { finish ( ) ; Intent i = new Intent ( ) ; i. setClass (sPlashScreen, Main. class ) ; startActivity (i ) ; stop ( ) ; } } } ; splashTread. start ( ) ; } @Override public boolean onTouchEvent (MotionEvent event ) { if (event. getAction ( ) == MotionEvent. ACTION_DOWN ) { synchronized (splashTread ) { splashTread. notifyAll ( ) ; } } return true ; } } |
希望大家都可以开发出漂亮又能赚钱的Android程序。