1

I'm using android.support.v4.view.ViewPager with cwac-pager to add or remove Fragments dynamically. Also this ViewPager has negative PageMargin and LayoutTransition (for API >= 11) animates for DISAPPEARING, CHANGE_APPEARING, CHANGE_DISAPPEARING. In layout, there is a Button calls mPagerAdapter.insert(pageDescriptor, mViewPager.getCurrentItem()) on click. When I click it, position of mViewPager automatically increases, so new page appears at the left of the current page. But I want to make new page appear at the center of screen.

I looked into the ViewPager code, and I think this part causing problem:

void dataSetChanged() {
    ...
    for (int i = 0; i < mItems.size(); i++) {
        final ItemInfo ii = mItems.get(i);
        final int newPos = mAdapter.getItemPosition(ii.object);
        ...
        if (ii.position != newPos) {
            if (ii.position == mCurItem) {
                // Our current item changed position. Follow it.
                newCurrItem = newPos;
            }

            ii.position = newPos;
            needPopulate = true;
        }
        ...
    }
    ...
}

The ideal scenario is:

  1. Click the add button
  2. notifyDataSetChanged() called without changes of mViewPager.getCurrentItem()
  3. Animation of CHANGE_APPEARING
  4. New page appears at the center of screen
Community
  • 1
  • 1
Yous
  • 728
  • 6
  • 22

0 Answers0