public class SplashActivity extends AppCompatActivity {
private RelativeLayout rl_splash;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
startAnim();
}
/**
* 开启动画
*/
private void startAnim() {
rl_splash = (RelativeLayout) findViewById(R.id.rl_splash);
// 动画集合
AnimationSet set = new AnimationSet(false);
// 旋转动画
RotateAnimation rotate = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotate.setDuration(1000);// 动画时间
rotate.setFillAfter(true);// 保持动画状态
// 缩放动画
ScaleAnimation scale = new ScaleAnimation(0, 1, 0, 1,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
scale.setDuration(1000);// 动画时间
scale.setFillAfter(true);// 保持动画状态
// 渐变动画
AlphaAnimation alpha = new AlphaAnimation(0, 1);
alpha.setDuration(2000);// 动画时间
alpha.setFillAfter(true);// 保持动画状态
set.addAnimation(rotate);
set.addAnimation(scale);
set.addAnimation(alpha);
// 设置动画监听
set.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
// 动画执行结束
@Override
public void onAnimationEnd(Animation animation) {
SharedPreferences sp=getSharedPreferences("config",MODE_PRIVATE);
boolean viewPagerShow=sp.getBoolean("viewPagerShow",false);
// System.out.println("有没有"+viewPagerShow);//第一次为false 后面都为true
//如果没有进入过引导页面false 进入引导页面ViewPagerActivity
if(viewPagerShow==false){
Intent intent =new Intent(SplashActivity.this,ViewPagerActivity.class);
startActivity(intent);
}
//如果进入过 true 进入主页面
else{
Intent intent=new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
}
finish();
}
});
rl_splash.startAnimation(set);
}
}