话不多说,先上图:
其实就是两个Activity,用动画过渡的效果。
先看第一个EnterActivity.
布局:
中间的View是为了给图片一个渐变效果,在black_bg中指定了gradient.
接下来就是在Activity中添加动画效果了.
/**
* Created by wonder on 2016/10/27.
*/
public class EntryActivity extends BaseActivity {
@BindView(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_screen_default,
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);
setTranslucentStatus(true);
Random random = new Random(SystemClock.currentThreadTimeMillis());
mSplashImage.setImageResource(IMAGES[random.nextInt(IMAGES.length)]);
Observable.timer(1000, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1() {
@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 AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
Intent intent = new Intent(EntryActivity.this, MainActivity.class);
startActivity(intent);
EntryActivity.this.finish();
overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
}
});
}
}
用了一个IMAGES数组是为了使动画多样化.使用RxJava的Observab在后台线程池中启动动画. AnimatorSet是一个动画集合,play(animatorX).with(animatorY)意味着在播放animatorX的同时播放animatorY. overridePendingTransition的两个参数是指进入动画和出去动画.注意:必须在starActivity或finish之后立即调用.
Demo中的参数为系统定义的,是淡入浅出的效果.当然也可以传入自定义的动画.