Weird issue when transitioning ImageView in Android 5.0

前端 未结 1 1563
长情又很酷
长情又很酷 2021-02-14 23:06

I\'m experiencing a strange issue / bug regarding ImageView transitions between Activities in Android 5.0.

I\'m trying to transition a thumbnail image from

相关标签:
1条回答
  • 2021-02-14 23:15

    Try adding the following code to your Fragment B's onCreateView() method:

    getActivity().postponeEnterTransition(); 
    scrollView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { 
        public boolean onPreDraw() { 
            scrollView.getViewTreeObserver().removeOnPreDrawListener(this);
            getActivity().startPostponedEnterTransition();
            return true;
        }
    });
    

    Does the problem still occur when this code is present? This will ensure that the transition only begins after the fragment has finished its layout.

    You might even need to call startPostponedEnterTransition() later than this... for example, if you are loading a high resolution image in your second activity, try calling startPostponedEnterTransition after the image has been loaded (i.e. set the onPreDraw listener on the ImageView instead of on the window's decor view).

    0 讨论(0)
提交回复
热议问题