Parent activity becomes invisible on exit transition

做~自己de王妃 提交于 2019-12-21 05:17:25

问题


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

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?

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

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

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).

How can I prevent this?

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?


回答1:


I was having the same problem when i use ActivityOptionsCompat.makeSceneTransitionAnimation. I resolved it by remove the activiy flag: android:launchMode="singleInstance" it may caused by different task can't use translation animation.




回答2:


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);
    }



回答3:


I was facing this problem before I realized that I was calling supportPostponeEnterTransition() without calling supportStartPostponedEnterTransition(). I had to call these because I was using Glide to load the image.



来源:https://stackoverflow.com/questions/28386493/parent-activity-becomes-invisible-on-exit-transition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!