5

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

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

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

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

4

1 回答 1

-1

我的解决方案是复制FragmentPagerAdapter类和setCustomAnimationsafterbeginTransaction方法:

@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的来源

于 2015-01-14T15:21:58.273 回答