javaandroidactivity-transition

setEnterTransition only shows Fade


I wrote an application with multiple activities in it.

I would like to add a transition in between (Slide).

I wrote the following code:

@Override
    protected void onCreate(Bundle savedInstanceState) {

        getWindow().requestFeature( Window.FEATURE_ACTIVITY_TRANSITIONS );
        getWindow().setEnterTransition( new Slide() );

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_profile );
        ....

And then when I click a button to open another activity I use:

Intent intent = new Intent( DiscoverActivity.this, UploadActivity.class );
                    startActivity( intent, ActivityOptions.makeSceneTransitionAnimation( this ).toBundle() );

However, no matter if I changed to Explore() or Fade() or Slide() it seems like it keeps showing me Fade.

Am I doing something wrong?

Thank you


Solution

  • You need to set setEnterTransition in the Activity You are opening not in the current Activity that's what the name suggest its a transition which will apply during entering in the Activity.

    Move the below code to UploadActivity. Also you can change the Gravity of Slide by passing it Gravity by default its Gravity.BOTTOM.

    getWindow().requestFeature( Window.FEATURE_ACTIVITY_TRANSITIONS );
    getWindow().setEnterTransition(new Slide(Gravity.END));