gpt4 book ai didi

java.lang.IllegalStateException : Page can only be offset by a positive amount

转载 作者:行者123 更新时间:2023-12-01 18:30:02 105 4
gpt4 key购买 nike

我在预启动报告中收到此错误,但它没有显示对我的 .java 文件的任何引用。谁能解释一下吗?

我正在使用 ViewPager2 (1.0.0) 进行页面转换。

Issue: java.lang.IllegalStateException: Page can only be offset by a positive amount, not by -54
FATAL EXCEPTION: main
Process: [redacted], PID: 18424
java.lang.IllegalStateException: Page can only be offset by a positive amount, not by -54
at androidx.viewpager2.widget.ScrollEventAdapter.updateScrollEventValues(ScrollEventAdapter.java:280)
at androidx.viewpager2.widget.ScrollEventAdapter.onScrolled(ScrollEventAdapter.java:178)
at androidx.recyclerview.widget.RecyclerView.dispatchOnScrolled(RecyclerView.java:5173)
at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5338)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:603)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5459)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

我找到了this page about ViewPager2引用 ViewPager2 的错误类似的错误。

可能相关:

我最近才开始收到此错误。我最近按以下方式更改了我的代码。我将重写 getItemCount() 方法,并且它返回的 NUM_PAGES 值会根据其他地方的 optional 而有所不同。以前,当切换此选项时,我只会 recreate() 保留所有 fragment 的 Activity。相反,现在我调用 Objects.requireNonNull(recyclerViewAdapter).notifyDataSetChanged(); 并且它工作得很好。我不确定这是否是添加/删除或显示/隐藏最右侧 fragment 的正确方法,因为其他选项会在 fragment 通常所在的位置留下一个空白页面。

编辑:我从 ViewPager2 中删除了我的 PageTransformer - 它仅设置 alpha - 并且错误当前已消失。但我认为这可能是巧合。我还没有在“野外”看到错误,只是间歇性地在发布前报告中看到错误。

编辑:我的 fragment 中没有带有布局动画的 View 组: Not animating ViewGroups

最佳答案

如果您的 ViewPager2 子 fragment 中的 ViewGroup 的 animateLayoutChanges 设置为 true,则可能会发生此错误。

如果是这种情况,您需要通过调用告诉 ViewGroup 仅对自己的布局更改进行动画处理,而不对 ViewPager2 的布局更改进行动画处理

viewGroup.layoutTransition.setAnimateParentHierarchy(false)

详情请参阅 that answer .

ViewPager2 documentation解释一下:

If your pages contain LayoutTransitions, then those LayoutTransitionsmust have animateParentHierarchy set to false.

Note that if you havea ViewGroup with animateLayoutChanges="true" in your layout xml file,a LayoutTransition is added automatically to that ViewGroup.

You willneed to manually callgetLayoutTransition().setAnimateParentHierarchy(false) on thatViewGroup after you inflated the xml layout.

关于java.lang.IllegalStateException : Page can only be offset by a positive amount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59660691/

105 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com