退出活动过渡时,父活动变得不可见 [英] Parent activity becomes invisible on exit transition

查看:168
本文介绍了退出活动过渡时,父活动变得不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用API​​ Level 21,并在Nexus 6上进行了测试.

I'm using API Level 21, testing on a Nexus 6.

我有两个活动:master + detail,每个视图都有一个片段. 当我在主列表中选择一个项目时,它将切换到详细信息视图.

I have two activities: master + detail, each view has a fragment. When I select an item in the master list it transitions to the detail view.

我已经在主视图和详细视图中启用了视图过渡,如下所示:

I have enabled view transitions in both master and detail, like this:

    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);

    Transition ts = new Slide(Gravity.RIGHT);
    ts.setDuration(2500);
    getWindow().setEnterTransition(ts);
    getWindow().setExitTransition(ts);

    getWindow().setAllowEnterTransitionOverlap(true);
    getWindow().setAllowReturnTransitionOverlap(true);

除了一件事以外,过渡动画均按预期工作:当我选择一个项目时,父活动在过渡时会隐藏起来,所以我看不到它.当我按回去时,局部视图被移出(不隐藏),而主视图被移入(不隐藏). 那么,为什么主视图过渡出来而细节视图过渡时却隐藏了呢?

The transition animations works as expected except for one thing: When I select an item, the parent activity gets hidden as it transitions out, so I can't see it. When I press back, the detail view is transitioned out (not hidden) and the master is transitioned in (not hidden). So why is the master view hidden when it transitions out and the detail view transitions in?

在Android Studio中,我看到了几条这样的日志:

In Android Studio I see several log posts such as this:

changeCanvasOpacity: opaque=true
changeCanvasOpacity: opaque=false
changeCanvasOpacity: opaque=false
changeCanvasOpacity: opaque=false

前两行用于第一个转换(主=>详细信息),后两行返回(详细=>主).如您所见,只有一行是"opaque = true".我相信那是在隐藏主视图时(过渡开始时).

The first two rows are for the first transition (master => detail) and the second two are back (detail => master). As you can see, only one row is "opaque = true". I believe that is when the master view is hidden (as the transition starts).

如何防止这种情况?

在此帖子中内容转换在-Depth(第2部分),在有内容的内容转换"和项目1C下,其显示框架将A中的所有转换视图设置为不可见."

In this post Content Transitions In-Depth (part 2), under "Content Transitions Under-The-Hood" and item 1C it says "The framework sets all transitioning views in A to INVISIBLE.".

我相信这是我的问题.我该如何解决?

I believe this is my issue. How can I resolve this?

推荐答案

我遇到了类似的问题,并在调用setContentView之后通过添加以下代码段在目标Activity的onCreate中解决了该问题:

I had a similar problem and solved it in onCreate of the target Activity by adding this snippet just after calling setContentView:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setEnterTransition(null);
    }

这篇关于退出活动过渡时,父活动变得不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆