一.禁止加载PreviewWindow
二.自定义PreviewWindow
三.自定义Preview Window增强版(动画)
这里我们要明确一点的是:Preview Window只是静态图,它本身是不展示动画的,我们这里的动画是在进入欢迎页之后才展示的。
1.设置mainActivity 的 theme 属性
2.在\res\values\style下 添加 Theme.Center
3.@drawable/splash_ico 内容
qq为图片4.mainActivity.xml
5.mainActivity.class
public class SplashActivity extends AppCompatActivity{
private ImageView img;
private ImageView ImgMark;
ViewPropertyAnimation.Animator animator=new ViewPropertyAnimation.Animator(){
@Override
public void animate(View view) {
view.setAlpha(0f);
ObjectAnimator objAnimator=ObjectAnimator.ofFloat(view,"alpha",0f,1f);
objAnimator.setDuration(2000);
objAnimator.start();
}
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
getWindow().setBackgroundDrawable(null);
initStatus();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_layout);
img= (ImageView) findViewById(R.id.img_id);
ImgMark= (ImageView) findViewById(R.id.icon_mark);
ImgMark.post(new Runnable() {
@Override
public void run() {
Glide.with(SplashActivity.this).load(R.drawable.benbenla)
.animate(animator).into(img);
startAnimat();
}
});
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
}
private void initStatus(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
View decoderView = getWindow().getDecorView();
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decoderView.setSystemUiVisibility(option);
getWindow().setStatusBarColor(Color.TRANSPARENT);
} else {
WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
//or ?
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
private void startAnimat(){
int imgHeight=ImgMark.getHeight()/5;
int height=getWindowManager().getDefaultDisplay().getHeight();
int curY=height/2 + imgHeight/2;
int dy=(height-imgHeight)/2;
AnimatorSet set=new AnimatorSet();
ObjectAnimator animatorTranslate=ObjectAnimator.ofFloat(ImgMark,"translationY",0,dy);
ObjectAnimator animatorScaleX=ObjectAnimator.ofFloat(ImgMark,"ScaleX",1f,0.2f);
ObjectAnimator animatorScaleY=ObjectAnimator.ofFloat(ImgMark,"ScaleY",1f,0.2f);
ObjectAnimator animatorAlpha=ObjectAnimator.ofFloat(ImgMark,"alpha",1f,0.5f);
set.play(animatorTranslate)
.with(animatorScaleX).with(animatorScaleY).with(animatorAlpha);
set.setDuration(1200);
set.setInterpolator(new AccelerateInterpolator());
set.start();
set.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
ImgMark.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this,MainActivity.class));
SplashActivity.this.finish();
}
},3000);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
}
网友评论