I'm using the ViewPager
from the compatibility library, with a FragmentStatePagerAdapter
.
I have a SherlockFragment
which is just a layout with a ViewPager
:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
style="@style/TitleStrip" />
</android.support.v4.view.ViewPager>
It has a few children displaying properly most of the time. Though when I want to replace this Fragment
using a FragmentTransaction
with an animation, its content (the showing child) disappears before the animation takes place. The only thing that remains is the PagerTitleStrip
. Here is the code I am using for the replacement:
Fragment fragment = new QueueListFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out);
ft.replace(R.id.fragment_holder, fragment);
ft.addToBackStack(null);
ft.commit();
From what I could check, onDestroyView
is called on the Fragment and its child Fragment before the transition begins, which looks odd to me. I would expect it to be called once the view is effectively replaced (after the transition).
The child fragment of the ViewPager
isn't at fault as I tried a very simple Fragment displaying a red layout and the problem is the same.
This issue doesn't happen with other kinds of fragments inside the application. The issue doesn't happen either if I use ft.add(R.id.fragment_holder, fragment)
instead of ft.replace(R.id.fragment_holder, fragment)
.
If anyone has a clue about that behavior, it would be greatly appreciated.