<bdo id='PW19Z'></bdo><ul id='PW19Z'></ul>

    <tfoot id='PW19Z'></tfoot>

  1. <i id='PW19Z'><tr id='PW19Z'><dt id='PW19Z'><q id='PW19Z'><span id='PW19Z'><b id='PW19Z'><form id='PW19Z'><ins id='PW19Z'></ins><ul id='PW19Z'></ul><sub id='PW19Z'></sub></form><legend id='PW19Z'></legend><bdo id='PW19Z'><pre id='PW19Z'><center id='PW19Z'></center></pre></bdo></b><th id='PW19Z'></th></span></q></dt></tr></i><div id='PW19Z'><tfoot id='PW19Z'></tfoot><dl id='PW19Z'><fieldset id='PW19Z'></fieldset></dl></div>
  2. <legend id='PW19Z'><style id='PW19Z'><dir id='PW19Z'><q id='PW19Z'></q></dir></style></legend>

  3. <small id='PW19Z'></small><noframes id='PW19Z'>

    1. ViewPager + PagerAdapter 在前两项后显示空白页

      时间:2023-10-04
      <i id='DXnhD'><tr id='DXnhD'><dt id='DXnhD'><q id='DXnhD'><span id='DXnhD'><b id='DXnhD'><form id='DXnhD'><ins id='DXnhD'></ins><ul id='DXnhD'></ul><sub id='DXnhD'></sub></form><legend id='DXnhD'></legend><bdo id='DXnhD'><pre id='DXnhD'><center id='DXnhD'></center></pre></bdo></b><th id='DXnhD'></th></span></q></dt></tr></i><div id='DXnhD'><tfoot id='DXnhD'></tfoot><dl id='DXnhD'><fieldset id='DXnhD'></fieldset></dl></div>

        <tfoot id='DXnhD'></tfoot>
          <bdo id='DXnhD'></bdo><ul id='DXnhD'></ul>

              <tbody id='DXnhD'></tbody>

            <small id='DXnhD'></small><noframes id='DXnhD'>

              • <legend id='DXnhD'><style id='DXnhD'><dir id='DXnhD'><q id='DXnhD'></q></dir></style></legend>
                本文介绍了ViewPager + PagerAdapter 在前两项后显示空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                发生了什么:前两个 ViewPager 页面加载良好(ViewPager 自动从当前页面加载 +-1).当您滚动过去时,不会显示下一页.以下问题的 GIF 演示.

                What's happening: The first two ViewPager pages loaded nicely (ViewPager automatically loads +-1 from current page). When you scroll past these the next pages aren't showing up. GIF demo of the problem below.

                调试信息:页面正在被实例化(参见下面的代码)并成功添加到 ViewPager ArrayListmItems(通过日志消息确认).我重新编译了带有 debug=true 集的 android.support.v4 库(aosp 中的 mmm frameworks/support/v4/),它显示一切正常,除了:

                Debug info: The pages are being instantiated (see code below) and are successfully added to the ViewPager ArrayList<ItemInfo>mItems (confirmed via Log messages). I recompiled the android.support.v4 library with debug=true set (mmm frameworks/support/v4/ in aosp) and it shows everything working perfectly EXCEPT:

                在加载前两个视图后,ViewPager 中的 onLayout 和 onMeasure 方法将停止调用.这意味着其他页面是黑色的,因为它们从未按照应有的方式进行测量和排列.我尝试在不同的点添加不同的 requestLayout() 调用以强制布局树刷新无济于事.

                The onLayout and onMeasure methods in ViewPager stop being called after the first two views are loaded. This means the other pages are black because they were never measured&arranged as they should have been. I tried adding different requestLayout() calls at different points to force a layout tree refresh to no avail.

                背景:我有一个通过 inflater.inflate 实例化并通过 view.findViewById(R.layouy.myid) 找到的 ViewPager.它直接替换了旧的 Gallery 视图,出于测试目的,PagerAdapter instantiateItem(collection, position) 只是这样做:

                Background: I have a ViewPager instantiated via inflater.inflate and found via view.findViewById(R.layouy.myid). It's directly replacing an old Gallery view, and for testing purposes the PagerAdapter instantiateItem(collection, position) simply does this:

                @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;
                }
                

                有什么想法吗?在我看来,PageView 的父母中的一些神秘设置以某种方式禁用了 onLayout PageView

                Any ideas? It looks to me like some mystery setting in PageView's parents are somehow disabling onLayout PageView

                推荐答案

                找到了我的问题.在我的视图的父级的父级中,有人继承了 LinearLayout 并覆盖了 requestLayout() 而没有调用 super.requestLayout().

                Found my problem. In the parent of the parent of my view someone subclassed LinearLayout and overrode requestLayout() without calling super.requestLayout().

                这破坏了我的视图层次结构的刷新,并阻止了 onMeasure 和 onLayout 在我的 ViewPager 上被调用.没有测量和布置页面,它们在 ViewPager 中显示为空白.

                This broke the refreshing of my view hierarchy and prevented onMeasure and onLayout from being called on my ViewPager. Without measuring and laying out the pages they showed up as blank in ViewPager.

                希望有一天这可以帮助其他人.我确实花了很长时间才弄清楚.

                Hope this helps someone else out someday. It sure took me forever to figure out.

                专业提示:android-sdk/tools/hierarchyviewer 令人难以置信.谢谢安卓团队.每个人都应该至少运行一次它,它对于调试和设计任何 UI 都是非常宝贵的.

                PRO TIP: android-sdk/tools/hierarchyviewer is incredible. Thank you Android team. Everyone should run it at least once, it can be invaluable in debugging and designing anything UI.

                这篇关于ViewPager + PagerAdapter 在前两项后显示空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:android viewpager中的幻灯片? 下一篇:ViewPager + SurfaceView = 导航回活动时的长时间延迟

                相关文章

                <tfoot id='eEcoY'></tfoot>

                1. <small id='eEcoY'></small><noframes id='eEcoY'>

                2. <legend id='eEcoY'><style id='eEcoY'><dir id='eEcoY'><q id='eEcoY'></q></dir></style></legend>
                  <i id='eEcoY'><tr id='eEcoY'><dt id='eEcoY'><q id='eEcoY'><span id='eEcoY'><b id='eEcoY'><form id='eEcoY'><ins id='eEcoY'></ins><ul id='eEcoY'></ul><sub id='eEcoY'></sub></form><legend id='eEcoY'></legend><bdo id='eEcoY'><pre id='eEcoY'><center id='eEcoY'></center></pre></bdo></b><th id='eEcoY'></th></span></q></dt></tr></i><div id='eEcoY'><tfoot id='eEcoY'></tfoot><dl id='eEcoY'><fieldset id='eEcoY'></fieldset></dl></div>

                      <bdo id='eEcoY'></bdo><ul id='eEcoY'></ul>