【问题标题】:Android L transition and home up buttonAndroid L 过渡和主页按钮
【发布时间】:2014-11-30 03:50:10
【问题描述】:

我正在使用新的 Android L 过渡,特别是与 Slide() 一起使用的共享元素过渡。当我按下后退按钮时,过渡效果很好,它会将共享的 ImageView 滑动并过渡到正确的位置,但是当我按下 ActionBar 中的主页按钮时,它会忽略新的过渡。

我在接收活动中设置了这段代码:

    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    getWindow().setExitTransition(new Slide());
    getWindow().setEnterTransition(new Slide());

我的“主要”活动中的这段代码:

    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    Transition transition = new Slide();
    getWindow().setSharedElementEnterTransition(transition);
    getWindow().setSharedElementExitTransition(transition);

【问题讨论】:

    标签: android android-transitions shared-element-transition


    【解决方案1】:

    确保在单击操作栏的向上按钮时调用finishAfterTransition()

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finishAfterTransition();             
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
    

    【讨论】:

    • 我当然会调用finish()。问题仍然存在,它没有做同样的动画。
    • @MaxKleine 抱歉,我原来的回答有错字。我的意思是finishAfterTransition()不是 finish()。我已经修改了我的帖子。
    猜你喜欢
    • 2018-08-12
    • 2012-10-28
    • 1970-01-01
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-20
    相关资源
    最近更新 更多