0

What is the simplest way to transition a fragment in Android?

I'm striving for a single line solution.

What I tried:

I added a transition xml file:

<?xml version="1.0" encoding="utf-8"?>
<transitionManager xmlns:android="http://schemas.android.com/apk/res/android">
    <fade xmlns:android="http://schemas.android.com/apk/res/android" />
</transitionManager>

And I'm using the following code to apply the above transition:

 EmailInfoFragment instanceFragment=
                    (EmailInfoFragment)getSupportFragmentManager().findFragmentById(R.id.emailInfoFrag);

            getSupportFragmentManager().beginTransaction().setTransition(1);
            instanceFragment.whatToShow(result);

I know that the code above is completely wrong, but this is something I'm trying to achieve, apply a very simple transition to a fragment on screen...

Draconar
  • 1,147
  • 1
  • 17
  • 36

2 Answers2

1

I think this is what you are looking for. also have a look at this.

Community
  • 1
  • 1
Samir
  • 3,139
  • 2
  • 17
  • 24
1

Would

getSupportFragmentManager.beginTransaction()
                    .replace(R.id.container, EmailInfoFragment.newInstance())
                    .commit();

work for you?

It switches from the currently active fragment to a new one aquired by EmailInfoFragment.newInstance(), which might aswell be new EmailInfoFragment() but seems to be used quite often and I kinda learned it that way...

Squirrelkiller
  • 2,575
  • 1
  • 22
  • 41