发生了什么:前两个ViewPager页面加载得很好(ViewPager自动从当前页面加载+ -1).当您滚动浏览这些页面时,下一页面不会显示.以下问题的GIF演示.
调试信息:该页面是被实例化(见下面的代码),并成功添加到ViewPager ArrayList<ItemInfo>mItems(通过日志消息确认).我android.support.v4用debug = true set(mmm frameworks/support/v4/在aosp中)重新编译了库,它显示了一切正常工作除了:
加载前两个视图后,将停止调用ViewPager中的onLayout和onMeasure方法.这意味着其他页面是黑色的,因为它们从未被测量和安排,因为它们应该是.我尝试在不同的点添加不同的requestLayout()调用以强制布局树刷新无效.
背景:我有一个通过inflater.inflate实例化的ViewPager,通过view.findViewById(R.layouy.myid)找到.它直接替换旧的Gallery视图,为了测试目的,PagerAdapter instantiateItem(集合,位置)只是这样做:
@Override
public Object instantiateItem(View collection, final int position) {
final TextView tv = new TextView(collection.getContext());
tv.setText("Looking at page " + position);
tv.setTextColor(Color.WHITE);
tv.setBackgroundColor(Color.rgb( (int)(Math.random()*100), (int)(Math.random()*100), (int)(Math.random()*100)));
tv.setTextSize(22);
((ViewPager) collection).addView(tv);
return tv;
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?在我看来,像PageView的父母的一些神秘设置在某种程度上禁用onLayout PageView