How to animate a view deleted from ViewPager?

I have a ViewPager in which I programmatically delete the view and set it to a new page, something like this:

private static class ProfilesPagerAdapter extends FragmentStatePagerAdapter
{
        private ArrayList<SherlockFragment> mViews = new ArrayList<SherlockFragment>();
        ...
}  

mProfilesPagerAdapter.mViews.remove(position);
mViewPager.setAdapter(mProfilesPagerAdapter);
mViewPager.setCurrentItem(newPos);

Is there a way to place the animation on the deleted view?

+5
source share
1 answer

My solution was to copy the class FragmentPagerAdapterand setCustomAnimationsafter beginTransaction:

@Override
public Object instantiateItem(ViewGroup container, int position) {
    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
        mCurTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
    }
    ...
}



@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
        mCurTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
    } 

    ...
}

Source FragmentPagerAdapter

-1
source

All Articles