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:
- Click the add button
notifyDataSetChanged()
called without changes ofmViewPager.getCurrentItem()
- Animation of
CHANGE_APPEARING
- New page appears at the center of screen