当前位置:   article > 正文

Android 加入启动页_android 启动页

android 启动页
static public View launcherView;

public static void showLauncher(){
    instance.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if(launcherView == null) {
                launcherView = LayoutInflater.from(instance).inflate(R.layout.launcher, null);
                FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                params.gravity = Gravity.CENTER;
                instance.addContentView(launcherView, params);
            }
        }
    });
}

public static void hideLauncher(){

    instance.runOnUiThread(new Runnable() {
        //这里加一个渐隐的动画
        @Override
        public void run() {
            if(launcherView != null) {
                AlphaAnimation mHideAnimation = new AlphaAnimation(1.0f, 0.0f);
                mHideAnimation.setDuration(200);
                mHideAnimation.setFillAfter(true);
                launcherView.startAnimation(mHideAnimation);
            }
        }
    });

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(250);
                instance.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (launcherView != null) {
                            ViewGroup vg = (ViewGroup) launcherView.getParent();
                            vg.removeView(launcherView);
                            launcherView = null;
                        }
                    }
                });
            } catch (InterruptedException e) {
                instance.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if(launcherView != null) {
                            ViewGroup vg = (ViewGroup) launcherView.getParent();
                            vg.removeView(launcherView);
                            launcherView = null;
                        }
                    }
                });
            }
        }
    }).start();
}
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/144711
推荐阅读