当然网上也有很多很好的例子.
那我就拿两种方式的闪屏来做效果,希望大家喜欢
1.首先讲个简单版的闪屏效果,主要为淡入淡出的效果
首先在res下创建文件夹anim,然后依次创建这2个文件
alpha_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" 动画起始时透明度; android:toAlpha="1.0" 动画结束时透明度 android:duration="1000" /> 动画持续使劲 </set>
alpha_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="1000" /> </set>
一进一出就形成了淡入淡出效果了,希望大家能想明白这个地方.
/** * 闪屏启动 * * @author Bert Guo 2013-3-1 */ public class AppStart extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); LinearLayout linear = new LinearLayout(AppStart.this); linear.setLayoutParams(new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); linear.setBackgroundDrawable(getResources().getDrawable(R.drawable.b1)); setContentView(linear); new CountDownTimer(2000, 1000) { // 倒计时启动界面效果 // 2000->从开始调用start()到倒计时完成并onFinish()方法被调用的毫秒数 // 1000->接收onTick(long)回调的间隔时间 @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { redirectTo(); } }.start(); } /** * 跳转到主界面 */ private void redirectTo() { UIHelper.Go(AppStart.this, MainActivity.class); // 跳转到MainActivity界面 int VERSION = Integer.parseInt(android.os.Build.VERSION.SDK); if (VERSION >= 5) { // 版本>=5 // 在startActivity后,加入overridePendingTransition实现淡入淡出效果 // 第一个activity退出时的动画,第二个activity进入时的动画 AppStart.this.overridePendingTransition(R.anim.alpha_out, R.anim.alpha_in); } finish(); // 销毁当前Activity } }
start.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="bottom" android:background="@drawable/b1"> </LinearLayout>
<activity android:name=".AppStart" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
MainActivity为一个普通界面就行..这是普通的,然后下面再讲一个动画效果的闪屏
提供点核心代码.
2.下面这个基本没见人去这么使用过,动画效果闪屏.
flg.xml
<?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="100" /> <item android:drawable="@drawable/f04" android:duration="100" /> <item android:drawable="@drawable/f05" android:duration="100" /> <item android:drawable="@drawable/f06" android:duration="100" /> <item android:drawable="@drawable/f07" android:duration="100" /> <item android:drawable="@drawable/f08" android:duration="100" /> <item android:drawable="@drawable/f09" android:duration="100" /> <item android:drawable="@drawable/f10" android:duration="100" /> </animation-list>
splash.xml
<?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> <!-- Not animated <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/SplashImageView" android:src="@drawable/lnxins" android:layout_gravity="center" > </ImageView> --> </LinearLayout>
appear.xml
<?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>
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>
SplashScreen
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(){ @Override 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(); } }