很多Android应用一开始都会有一个欢迎界面,淡入淡出效果也是用得非常多的,下面来实现一下。
主要代码如下:
package com.myaibang.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new CountDownTimer(2000,1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
Intent intent = new Intent();
intent.setClass(MainActivity.this, SecondActivity.class);
startActivity(intent);
int VERSION=Integer.parseInt(android.os.Build.VERSION.SDK);
if(VERSION >= 5){
MainActivity.this.overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
}
finish();
}
}.start();
}
}
还需要两个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=”2000″ />
</set>
<?xml version=”1.0″ encoding=”UTF-8″?>
<set
xmlns:android=”http://schemas.android.com/apk/res/android”>
<alpha
android:fromAlpha=”1.0″
android:toAlpha=”0.0″
android:duration=”2000″ />
</set>
这就实现了淡入淡出效果,还不错哦!试试吧!