如何为从ViewPager中删除的视图设置动画?

时间:2013-04-29 16:11:20

标签: android

我有一个ViewPager,我在其中以编程方式删除视图并将其设置为新页面,有点像这样:

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

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

有没有办法可以在要移除的视图上放置动画?

1 个答案:

答案 0 :(得分:-1)

我的解决方案是在FragmentPagerAdapter方法之后复制setCustomAnimations课程和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);
    } 

    ...
}

FragmentPagerAdapter

的来源