Blinking screen on image transition between activities

后端 未结 12 2196
温柔的废话
温柔的废话 2020-12-02 07:01

I implemented an image transition between two activities using the new shared elements from lollipop. It\'s working but I get a weird white blinking on the entire screen du

相关标签:
12条回答
  • 2020-12-02 07:34

    Some useful answers above. As far as I understand this is caused by activity transition overlap. To overcome this issue I have used the following values in the onCreate() methods of both activities:

    getWindow().setAllowEnterTransitionOverlap(false);
    getWindow().setAllowReturnTransitionOverlap(false);
    
    0 讨论(0)
  • 2020-12-02 07:36

    In my situation, the second activity did not have a status bar which was defined in the activity theme with this tag.

    <item name="android:windowFullscreen">true</item>
    

    Since it was not mandatory to hide the status bar in portrait mode, I removed this tag and manually hide/show the status bar when needed and the blinking is gone.

    0 讨论(0)
  • 2020-12-02 07:43

    Make some method in helper like

    public static Transition makeEnterTransition() {
        Transition fade = new Fade();
        fade.excludeTarget(android.R.id.navigationBarBackground, true);
        fade.excludeTarget(android.R.id.statusBarBackground, true);
        return fade;
    }
    

    Execute it in the activity that you are starting like this

    getWindow().setEnterTransition(TransitionUtils.makeEnterTransition());
    

    Source https://github.com/alexjlockwood/custom-lollipop-transitions/

    0 讨论(0)
  • 2020-12-02 07:43

    Add these codes inside onCreate of both Activities where you doing Transition elements

       Fade fade = new Fade();
            View decor = getWindow().getDecorView();
            fade.excludeTarget(decor.findViewById(R.id.action_bar_container),true);
            fade.excludeTarget(android.R.id.statusBarBackground,true);
            fade.excludeTarget(android.R.id.navigationBarBackground,true);
    
            getWindow().setEnterTransition(fade);
            getWindow().setExitTransition(fade);
    

    This will exclude the animation from the navigation and status bar, So no more blinking

    0 讨论(0)
  • 2020-12-02 07:43

    Elements fade in and out, unless you specify explicitly they are the same on both activities. That includes status and navigation bar.

    In your particular case, I would add the toolbar and these two views to the shared elements list:

    List<Pair> viewPairs = new ArrayList<>();
    viewPairs.add(Pair.create(findViewById(android.R.id.statusBarBackground), Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME));
    viewPairs.add(Pair.create(findViewById(android.R.id.navigationBarBackground), Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME));
    // Add your views...
    
    Pair[] array = new Pair[viewPairs.size()];
    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), viewPairs.toArray(array)).toBundle();
    // ...
    
    ActivityCompat.startActivity(activity, intent, options.toBundle());
    
    0 讨论(0)
  • 2020-12-02 07:45
    <!-- edit in your theme -->
    <item name="android:windowEnterTransition">@android:transition/no_transition</item>
    <item name="android:windowExitTransition">@android:transition/no_transition</item>
    
    0 讨论(0)
提交回复
热议问题