效果图:
为了录制效果配置为渐隐了。和主activity放在一块的话,当主activity被系统回收之后再次回到主activity时会再次执行onCreate,但开启动画一般只是第一次进入应用时执行一次,在应用里面不应该再次出现。因此单独使用了一个activity来做超首开启动画的特效,主要是使用了alpha动画特效
主要代码:
frist_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/ivOpenImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/open_bg2"
android:src="@drawable/open_bg" />
</LinearLayout>
first_alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<alpha
android:duration="500"
android:fromAlpha="1.0"
android:toAlpha="1.0" />
</set>
FirstActivity
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
/**
* 开启动画
*
* @author qhg
* @date 2014年3月4日
*
*/
public class FirstActivity extends Activity {
private ImageView imageView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);// 去掉信息栏
setContentView(R.layout.frist_main);
// 监听动画完成之后启动MainActivity
Animation animation = AnimationUtils.loadAnimation(this,
R.anim.first_alpha);
animation.setFillAfter(true);
imageView = (ImageView) findViewById(R.id.ivOpenImage);
imageView.startAnimation(animation);
animation.setAnimationListener(new MyAnimationListener());
}
/**
* 监听开启动画
*
* @author Administrator
*
*/
class MyAnimationListener implements AnimationListener {
public void onAnimationStart(Animation animation) {
}
/**
* 动画结束时打开MainActivity,释放FirstActivity
*/
public void onAnimationEnd(Animation animation) {
Intent intent = new Intent();
intent.setClass(FirstActivity.this, MainActivity.class);
startActivity(intent);
//释放FirstActivity
FirstActivity.this.finish();
}
public void onAnimationRepeat(Animation animation) {
}
}
}