Android开机启动动画

来源:互联网 发布:mysql 默认端口号 编辑:程序博客网 时间:2024/04/28 06:03

本程序在别人的代码的基础上更改而成。

下载地址:http://download.csdn.net/detail/hong0220/4670232

核心代码:

SplashScreen.java

[java] view plaincopy
  1. package com.yourname.main;  
  2. import android.app.Activity;  
  3. import android.content.Intent;  
  4. import android.graphics.drawable.AnimationDrawable;  
  5. import android.os.Bundle;  
  6. import android.view.Menu;  
  7. import android.view.MotionEvent;  
  8. import android.widget.ImageView;  
  9.   
  10. public class SplashScreen extends Activity {  
  11.     private Thread mSplashThread;     
  12.     @Override  
  13.     public void onCreate(Bundle savedInstanceState) {  
  14.         super.onCreate(savedInstanceState);  
  15.         setContentView(R.layout.splash);  
  16.         final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);  
  17.         splashImageView.setBackgroundResource(R.drawable.flag);  
  18.         final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();  
  19.         splashImageView.post(new Runnable(){  
  20.             @Override  
  21.             public void run() {  
  22.                 frameAnimation.start();               
  23.             }             
  24.         });  
  25.         mSplashThread =  new Thread(){  
  26.             @Override  
  27.             public void run(){  
  28.                 try {  
  29.                     synchronized(this){  
  30.                         wait(10000);  
  31.                     }  
  32.                 }   
  33.                 catch(InterruptedException ex){                   
  34.                 }  
  35.                 finish();             
  36.             }  
  37.         };  
  38.         mSplashThread.start();  
  39.     }  
  40.   
  41.     @Override  
  42.     public boolean onTouchEvent(MotionEvent evt)  
  43.     {  
  44.         if(evt.getAction() == MotionEvent.ACTION_DOWN)  
  45.         {  
  46.             synchronized(mSplashThread){  
  47.                 finish();  
  48.             }  
  49.         }  
  50.         return true;  
  51.     }  
  52. }  


BootBroadcastReceiver.java

[java] view plaincopy
  1. package com.yourname.main;  
  2. import android.content.BroadcastReceiver;  
  3. import android.content.Context;  
  4. import android.content.Intent;  
  5.   
  6. public class BootBroadcastReceiver extends BroadcastReceiver {  
  7.     static final String ACTION = "android.intent.action.BOOT_COMPLETED";  
  8.    
  9.     @Override  
  10.     public void onReceive(Context context, Intent intent) {  
  11.         if (intent.getAction().equals(ACTION)){  
  12.                 Intent sayHelloIntent=new Intent(context,SplashScreen.class);  
  13.                 sayHelloIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  14.                 context.startActivity(sayHelloIntent);  
  15.         }  
  16.     }  
  17. }  


配置文件

AndroidManifest.xml

[plain] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.       package="com.yourname.main"  
  4.       android:versionCode="1"  
  5.       android:versionName="1.0">  
  6.     <application android:icon="@drawable/icon" android:label="@string/app_name">  
  7.         <activity   
  8.             android:name="SplashScreen"  
  9.             android:theme="@style/Theme.Transparent">  
  10.             <intent-filter>  
  11.                 <action android:name="android.intent.action.MAIN"></action>  
  12.                 <category android:name="android.intent.category.LAUNCHER"></category>  
  13.             </intent-filter>  
  14.         </activity>  
  15.         <receiver android:name=".BootBroadcastReceiver">  
  16.             <intent-filter>  
  17.                 <action android:name="android.intent.action.BOOT_COMPLETED"/>  
  18.                 <category android:name="android.intent.category.LAUNCHER"/>  
  19.             </intent-filter>  
  20.         </receiver>  
  21.     </application>  
  22.     <uses-sdk android:minSdkVersion="7" />      
  23. </manifest>   


layout/splash.xml

[plain] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout  
  3.   xmlns:android="http://schemas.android.com/apk/res/android"  
  4.   android:layout_width="wrap_content"  
  5.   android:layout_height="wrap_content"   
  6.   android:id="@+id/TheSplashLayout"  
  7.   android:layout_gravity="center"  
  8.   >  
  9.     <ImageView   
  10.         android:layout_width="wrap_content"   
  11.         android:layout_height="wrap_content"   
  12.         android:id="@+id/SplashImageView"  
  13.         android:layout_gravity="center"       
  14.         >  
  15.     </ImageView>  
  16. </LinearLayout>  


values/styles.xml

[plain] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <style   
  4.         name="SplashScreen">  
  5.         parent="@android:Animation"   
  6.         <item name="android:windowEnterAnimation">@drawable/appear</item>  
  7.         <item name="android:windowExitAnimation">@drawable/disappear</item>   
  8.     </style>   
  9.     <style   
  10.         name="Theme.Transparent"   
  11.         parent="android:Theme">  
  12.         <item name="android:windowIsTranslucent">true</item>  
  13.         <item name="android:windowBackground">@android:color/transparent</item>  
  14.         <item name="android:windowNoTitle">true</item>  
  15.         <item name="android:windowAnimationStyle">@style/SplashScreen</item>                  
  16.     </style>        
  17. </resources>  


drawable/flag.xml

[plain] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <animation-list    
  3.     xmlns:android="http://schemas.android.com/apk/res/android"   
  4.     android:id="@+id/flaganim"  
  5.     android:oneshot="false"  
  6.     >  
  7.     <item android:drawable="@drawable/f03" android:duration="1000" />  
  8.     <item android:drawable="@drawable/f04" android:duration="1000" />  
  9.     <item android:drawable="@drawable/f05" android:duration="1000" />  
  10.     <item android:drawable="@drawable/f06" android:duration="1000" />  
  11.     <item android:drawable="@drawable/f07" android:duration="1000" />  
  12.     <item android:drawable="@drawable/f08" android:duration="1000" />  
  13.     <item android:drawable="@drawable/f09" android:duration="1000" />  
  14.     <item android:drawable="@drawable/f10" android:duration="1000" />   
  15. </animation-list>  

drawable/appear.xml

[plain] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <alpha  
  4.         android:interpolator="@android:anim/accelerate_interpolator"  
  5.         android:fromAlpha="0.0" android:toAlpha="1.0"  
  6.         android:duration="800"  
  7.     />  
  8. </set>  

Drawable/disappear.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"><alphaandroid:interpolator="@android:anim/decelerate_interpolator"android:fromAlpha="1.0" android:toAlpha="0.0"android:duration="800"/></set>