您的位置:首页 > 移动开发 > Android开发

Android开机启动动画

2012-10-21 17:59 330 查看
本程序在别人的代码的基础上更改而成。

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

核心代码:

SplashScreen.java

[java] view
plaincopy

package com.yourname.main;

import android.app.Activity;

import android.content.Intent;

import android.graphics.drawable.AnimationDrawable;

import android.os.Bundle;

import android.view.Menu;

import android.view.MotionEvent;

import android.widget.ImageView;



public class SplashScreen extends Activity {

private Thread mSplashThread;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.splash);

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

splashImageView.setBackgroundResource(R.drawable.flag);

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

splashImageView.post(new Runnable(){

@Override

public void run() {

frameAnimation.start();

}

});

mSplashThread = new Thread(){

@Override

public void run(){

try {

synchronized(this){

wait(10000);

}

}

catch(InterruptedException ex){

}

finish();

}

};

mSplashThread.start();

}



@Override

public boolean onTouchEvent(MotionEvent evt)

{

if(evt.getAction() == MotionEvent.ACTION_DOWN)

{

synchronized(mSplashThread){

finish();

}

}

return true;

}

}

BootBroadcastReceiver.java

[java] view
plaincopy

package com.yourname.main;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;



public class BootBroadcastReceiver extends BroadcastReceiver {

static final String ACTION = "android.intent.action.BOOT_COMPLETED";



@Override

public void onReceive(Context context, Intent intent) {

if (intent.getAction().equals(ACTION)){

Intent sayHelloIntent=new Intent(context,SplashScreen.class);

sayHelloIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(sayHelloIntent);

}

}

}

配置文件

AndroidManifest.xml

[plain] view
plaincopy

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.yourname.main"

android:versionCode="1"

android:versionName="1.0">

<application android:icon="@drawable/icon" android:label="@string/app_name">

<activity

android:name="SplashScreen"

android:theme="@style/Theme.Transparent">

<intent-filter>

<action android:name="android.intent.action.MAIN"></action>

<category android:name="android.intent.category.LAUNCHER"></category>

</intent-filter>

</activity>

<receiver android:name=".BootBroadcastReceiver">

<intent-filter>

<action android:name="android.intent.action.BOOT_COMPLETED"/>

<category android:name="android.intent.category.LAUNCHER"/>

</intent-filter>

</receiver>

</application>

<uses-sdk android:minSdkVersion="7" />

</manifest>

layout/splash.xml

[plain] view
plaincopy

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/TheSplashLayout"

android:layout_gravity="center"

>

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/SplashImageView"

android:layout_gravity="center"

>

</ImageView>

</LinearLayout>

values/styles.xml

[plain] view
plaincopy

<?xml version="1.0" encoding="utf-8"?>

<resources>

<style

name="SplashScreen">

parent="@android:Animation"

<item name="android:windowEnterAnimation">@drawable/appear</item>

<item name="android:windowExitAnimation">@drawable/disappear</item>

</style>

<style

name="Theme.Transparent"

parent="android:Theme">

<item name="android:windowIsTranslucent">true</item>

<item name="android:windowBackground">@android:color/transparent</item>

<item name="android:windowNoTitle">true</item>

<item name="android:windowAnimationStyle">@style/SplashScreen</item>

</style>

</resources>

drawable/flag.xml

[plain] view
plaincopy

<?xml version="1.0" encoding="utf-8"?>

<animation-list

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/flaganim"

android:oneshot="false"

>

<item android:drawable="@drawable/f03" android:duration="1000" />

<item android:drawable="@drawable/f04" android:duration="1000" />

<item android:drawable="@drawable/f05" android:duration="1000" />

<item android:drawable="@drawable/f06" android:duration="1000" />

<item android:drawable="@drawable/f07" android:duration="1000" />

<item android:drawable="@drawable/f08" android:duration="1000" />

<item android:drawable="@drawable/f09" android:duration="1000" />

<item android:drawable="@drawable/f10" android:duration="1000" />

</animation-list>


drawable/appear.xml

[plain] view
plaincopy

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha

android:interpolator="@android:anim/accelerate_interpolator"

android:fromAlpha="0.0" android:toAlpha="1.0"

android:duration="800"

/>

</set>

Drawable/disappear.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<alpha
		android:interpolator="@android:anim/decelerate_interpolator"
		android:fromAlpha="1.0" android:toAlpha="0.0"
		android:duration="800"
	/>
</set>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: