现在市面上很多应用都有启动图。启动图的作用可以介绍应用,也可以给用户进入应用一个缓冲的作用。
下边看一下简单启动图的效果:
public class EntryActivity extends Activity {
@Bind(R.id.iv_entry)
ImageView mSplashImage;
private static final int ANIMATION_TIME = 2000;
private static final float SCALE_END = 1.13F;
private static final int[] IMAGES = {
R.drawable.ic_hotbitmapgg,
R.drawable.splash0,
R.drawable.splash1,
R.drawable.splash2,
R.drawable.splash3,
R.drawable.splash4,
R.drawable.splash5,
R.drawable.splash6,
R.drawable.splash7,
R.drawable.splash8,
R.drawable.splash9,
R.drawable.splash10,
R.drawable.splash11,
R.drawable.splash12,
R.drawable.splash13,
R.drawable.splash14,
R.drawable.splash15,
R.drawable.splash16,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entry);
ButterKnife.bind(this);
Random random = new Random(SystemClock.elapsedRealtime());
mSplashImage.setImageResource(IMAGES[random.nextInt(IMAGES.length)]);
Observable.timer(1, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Long>(){
@Override
public void call(Long aLong) {
startAnim();
}
});
}
private void startAnim() {
ObjectAnimator animatorX=ObjectAnimator.ofFloat(mSplashImage,"scaleX",1f,SCALE_END);
ObjectAnimator animatorY=ObjectAnimator.ofFloat(mSplashImage,"scaleY",1f,SCALE_END);
AnimatorSet set=new AnimatorSet();
set.setDuration(ANIMATION_TIME).play(animatorX).with(animatorY);
set.start();
set.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
startActivity(new Intent(EntryActivity.this,MainActivity.class));
EntryActivity.this.finish();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
}
网友评论