安卓启动画面的最佳实践

2020-07-21  本文已影响0人  天下第九九八十一

(忽略调试黑框)

这是debug模式下的冷启动画面,实际启动要快得多,基本上一闪而过。

附Gif制作技巧:

参考 https://www.jianshu.com/p/a11bbf804e75

不要用启动图activity,基本上没什么用,除非你想让用户定制背景。做法是style里面写好窗体背景,然后oncreate之时让其淡出,最终将其设空:

<item name="android:windowBackground">@drawable/flash_screen</item>
boolean transit = opt.getTransitSplashScreen(); //是否淡出启动图
        if(!transit) setTheme(R.style.AppThemeNormal);
        
        setContentView(R.layout.activity_main);
        
        View rootView=findViewById(R.id.root);
                
        if(transit){
            rootView.setAlpha(0);
            ObjectAnimator fadeInContents = ObjectAnimator.ofFloat(rootView, "alpha", 0, 1);
            fadeInContents.setInterpolator(new AccelerateDecelerateInterpolator());
            fadeInContents.setDuration(350);
            fadeInContents.addListener(new Animator.AnimatorListener() {
                @Override public void onAnimationStart(Animator animation) { }
                @Override public void onAnimationEnd(Animator animation) {
                    getWindow().setBackgroundDrawable(null);
                }
                @Override public void onAnimationCancel(Animator animation) { }
                @Override public void onAnimationRepeat(Animator animation) { }
            });
            rootView.post(fadeInContents::start);
        }

说是淡出启动图,其实是淡入内容页面。

注意,广告页只是广告页,不算正常的启动页。为什么要有启动页?仅仅是用于避免闪白而已,逼格算其次,启动页绝不能拖慢正常的启动速度。

背景图写法:

参考 https://stackoverflow.com/questions/10574363/android-splash-screen-image-sizes-to-fit-all-devices#answer-33366007

v23以上可以直接上vector。大屏幕尺寸可以调大一些。

上一篇 下一篇

猜你喜欢

热点阅读