Android reverse shared element transition on back after orientation change?

前端 未结 4 1432
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 14:20

For shared element transition I am following this github project. It has 2 screens - one with recyclerview having number of cards & second the detail screen. As expected

4条回答
  •  感动是毒
    2020-12-31 15:05

    You have to set:

    requestWindowFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    requestWindowFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
    

    in the calling and the called activity (MainActivity + NextActivity in this example).

    I assume you open the NextActivity by calling:

    ActivityOptions options = ActivityOptions.
          makeSceneTransitionAnimation(this, new Pair(viewToAnimate, "animationName"));
    Intent intent = new Intent(MainActivity.this, NextActivity.class);
    startActivity(intent, options.toBundle());
    

    In the NextActivity you have to add:

    animatingView.setTransitionName("animationName");
    

    If you do this the transition will work if you tap the back button.

    BUT if you turn the device and press the back button it won't work.

    To solve this problem i added this in the first activity (MainActivity in this example):

    animatingView.setTransitionName("animationName");
    

    The system now knows what to animate after a screen rotation.

提交回复
热议问题