进入应用动画闪屏, android5.0初始动画,不执行解决等方案总结

来源:互联网 发布:表单大师软件 编辑:程序博客网 时间:2024/06/18 15:18
 这个问题是这几天还在开发中遇到的问题,困扰了我几天终于改决了,现在记录下。
              如果你的应用非常小有可能是遇不到这个问题的。
              一.系统5.0以下解决方案:在oncreate方法中做一下线程延迟,大概几十毫秒就可以了。

              二.系统5.0中的onCreate方法使用属性动画一点效果都没有(根本不会动),可以使用handle的延迟方法

                 

 new Handler().postDelayed(new Runnable() {                        @Override            public void run() {                // TODO Auto-generated method stub                ObjectAnimator animator=ObjectAnimator.ofFloat(target, propertyName, values);                ...                animator.start();            }        }, 100);
 就有作用了。

三,虽然这样解决了问题,但都不是很好的方法,也没有从根本上解决问题。我又新建了工程(就一个按钮的布局),并没有出现上面  的情况。我把公司项目里加载so库的方法注释掉,发现动画也流畅了很多。所以要解决问题,根本还是要从,项目的优化入手
 但上面的领导不同意现有的框架的大的改动,也不同意再多做一个activity动画完了,再跳过来。
 最后我也在想在activity里面是否可以setContentView()再次,如果可以就可以像跳activity一样了,结果是可以的 。

 说到这里可能大家也想到方法 ,对的,就是先用一张图片和主界面一样的图片先做动画。 动画完了,再setContentView真的布局,再加载:

<span style="font-size:12px;">@Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);                      ImageView image=new ImageView(this);        image.setBackgroundRerouse(...);        setContentView(inflate);        try {            Thread.sleep(150);        } catch (Exception e1) {            e1.printStackTrace();        }        //动画        AnimatorUtils.addAnimator(image, this, R.animator.gaaaainit);        Animator startParallelExecuteAnimators = AnimatorUtils.startParallelExecuteAnimators();        startParallelExecuteAnimators.addListener(new ViewUtil.AnimListener() {             @Override            public void onAnimationEnd(Animator animation) {                //动画完后,加载真的布局及数据                inflate = LayoutInflater.from(this).inflate(R.layout.home_horizontalinit, null);                setContentView(inflate);                GlaNative.setIUpdateViewContext(home_horizontalActivity.this, "home_horizontal");                CurPageName = "homeaction";                GlaNative.InitResolution(home_horizontalActivity.this, R.drawable.home_horizontalbackground,                        CurPageName, 0);                m_gestureDetector = new GestureDetector(home_horizontalActivity.this);                m_gestureDetector.setIsLongpressEnabled(true);                Bundle bundle = new Bundle();                bundle = home_horizontalActivity.this.getIntent().getExtras();                。。。</span>

                 

1 0
原创粉丝点击