ActivityOptions.makeSceneTransitionAnimation doesn't seem to exist

后端 未结 3 1387
南笙
南笙 2020-12-30 13:30

Android L introduced a new animations feature: animating between similar Views in different activities. It\'s documented here.

I\'ve tried to use ActivityOpti

3条回答
  •  一个人的身影
    2020-12-30 14:31

    Here is something work with 5.0 sdk got after 10/17/14.

    But not sure what is the expected behavior if enable window content transitions and called setEnterTransition/setExitTransition in both mainActivity and secondActivity. If they are different (e.g one choose Explode and other choose Slide), which one would be applied?

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            /*
            To enable window content transitions in your code instead, call the Window.requestFeature() method:
             */
            getWindow().requestFeature(android.view.Window.FEATURE_CONTENT_TRANSITIONS);
            Transition ts = new Explode();  //Slide(); //Explode();
    
            ts.setStartDelay(2000);
            ts.setDuration(5000);
    
            /*
            If you have set an enter transition for the second activity,
            the transition is also activated when the activity starts.
             */
    
            getWindow().setEnterTransition(ts);
            getWindow().setExitTransition(ts);
    
    
            setContentView(R.layout.activity_main_view);
            if (savedInstanceState == null) {
                getFragmentManager().beginTransaction()
                        .add(R.id.container, mainViewFragment.newInstance())
                        .commit();
            }
        }
    
        public void launchSecondActivity() {
    
                /*
                If you enable transitions and set an exit transition for an activity,
                the transition is activated when you launch another activity as follows:
                 */
    
                Intent listIntent = new Intent(this, secondActivity.class);
                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
    
            }
    
    }
    

    //===

    public class secondActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            ///
            getWindow().requestFeature(android.view.Window.FEATURE_CONTENT_TRANSITIONS);
            Transition ts = new Slide();  //Slide(); //Explode();
    
            ts.setDuration(3000);
    
            getWindow().setEnterTransition(ts);
            getWindow().setExitTransition(ts);
    
            ///
    
            setContentView(R.layout.activity_scene_transition);
            if (savedInstanceState == null) {
                getFragmentManager().beginTransaction()
                        .add(R.id.container, new PlaceholderFragment())
                        .commit();
            }
        }
    

提交回复
热议问题