这是我的视图层次结构:
第一个片段有一个WebView
(根是WebView
)。
当在页面之间快速切换时,最终会出现此错误(随机发生,或在我无法确定的某个位置),从具有WebView
的片段向右滑动它。
如果我在不包含WebViews的片段之间滑动,则无论我滑动多快或多少次,它都可以正常工作。
Stacktrace:
java.lang.IndexOutOfBoundsException: getChildDrawingOrder() returned invalid index 1 (child count is 1)
at android.view.ViewGroup.getAndVerifyPreorderedIndex(ViewGroup.java:2055)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4190)
at android.view.View.draw(View.java:21956)
at android.view.View.updateDisplayListIfDirty(View.java:20830)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.updateDisplayListIfDirty(View.java:20821)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.updateDisplayListIfDirty(View.java:20821)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4217)
at android.view.View.draw(View.java:21956)
at androidx.viewpager.widget.ViewPager.draw(ViewPager.java:2426)
at android.view.View.updateDisplayListIfDirty(View.java:20830)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.updateDisplayListIfDirty(View.java:20821)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.updateDisplayListIfDirty(View.java:20821)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.updateDisplayListIfDirty(View.java:20821)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.updateDisplayListIfDirty(View.java:20821)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.updateDisplayListIfDirty(View.java:20821)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.updateDisplayListIfDirty(View.java:20821)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.updateDisplayListIfDirty(View.java:20821)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.updateDisplayListIfDirty(View.java:20821)
at android.view.View.draw(View.java:21685)
at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
at android.view.View.draw(View.java:21956)
at com.android.internal.policy.DecorView.draw(DecorView.java:795)
at android.view.View.updateDisplayListIfDirty(View.java:20830)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:575)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:581)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:654)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3761)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3489)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2777)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1745)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7730)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
at android.view.Choreographer.doFrame(Choreographer.java:725)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7116)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)
答案 0 :(得分:0)
对于我来说,很难理解为什么为什么IndexOutOfBoundException
却看不到代码的某些部分。但是,我可以假定,在加载带有Fragment
的{{1}}时,它正在尝试使用一些尚不可用的资源。因此,我想提出一个解决方法。
您可能会考虑设置WebView
,以便即使您一直向下滑动也不会重新加载片段。以下是示例代码。
setOffscreenPageLimit
我希望能解决您的问题。