在其他支持ViewPager循環並提高性能的應用程序中,應該使用View而不是Fragment。基本上這是instantiateItem
你正在尋找。
@Override
public Object instantiateItem(ViewGroup parent, int position) {
int viewType = getItemViewType(position);
if (!mRecycleCacheMap.containsKey(viewType)) {
mRecycleCacheMap.put(viewType, new RecycleCache(this, parent, viewType));
}
ViewHolder viewHolder = mRecycleCacheMap.get(viewType).getFreeViewHolder();
viewHolder.mIsAttached = true;
onBindViewHolder((VH) viewHolder, position);
parent.addView(viewHolder.mItemView);
if (DEBUG) {
Log.i(TAG, String.format(Locale.US, "instantiateItem | position: %d | viewType: %d | cacheCount: %d",
position, viewType, mRecycleCacheMap.get(viewType).mCaches.size()));
}
return viewHolder;
}
這裏RecyclerPagerAdapter
看看我的示例代碼這會讓你viewpager掛了很多,不會有平滑滾動可言! – Antrromet 2014-12-13 16:06:07
@Antrromet那麼你的建議是什麼? – NeoWang 2014-12-13 16:12:39
看看[FragmentStatePagerAdapter](http://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html) – mpkuth 2014-12-13 19:58:25