gpt4 book ai didi

android - 共享元素过渡到包含 ViewPager 的 fragment

转载 作者:行者123 更新时间:2023-12-04 12:09:27 29 4
gpt4 key购买 nike

我正在尝试执行从 fragment A 中的 RecyclerView 项目到 fragment B 的共享元素转换。转换名称设置在两个布局中最外层的 CardViews 上。我的实现与this中的实现基本相同样本。
一切正常,直到我在 Fragment B 中添加了 ViewPager2。
我尝试按照 this 中的步骤进行操作回答,但没有运气。
堆栈跟踪:

java.lang.IndexOutOfBoundsException: Index: 5, Size: 5
at java.util.ArrayList.get(ArrayList.java:437)
at androidx.fragment.app.FragmentTransitionImpl.setNameOverridesReordered(FragmentTransitionImpl.java:182)
at androidx.fragment.app.DefaultSpecialEffectsController.startTransitions(DefaultSpecialEffectsController.java:665)
at androidx.fragment.app.DefaultSpecialEffectsController.executeOperations(DefaultSpecialEffectsController.java:114)
at androidx.fragment.app.SpecialEffectsController.executePendingOperations(SpecialEffectsController.java:294)
at androidx.fragment.app.Fragment$3.run(Fragment.java:2776)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
编辑:显示我的依赖项以响应建议 Fragment 版本需要更新的答案:
ext.kotlin_version = "1.5.10"
ext.navigation_version="2.4.0-alpha02"

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation "androidx.work:work-runtime-ktx:2.5.0"

// Navigation
implementation "androidx.navigation:navigation-runtime-ktx:$navigation_version"
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"

最佳答案

该错误是在 androidx.fragment:fragment:1.3.4 上引入的。 .要修复它,您需要手动更新到 androidx.fragment:fragment:1.3.5androidx.fragment:fragment-ktx:1.3.5 .
根据release notes

Fixed a regression in shared element transitions introduced in Fragment 1.3.4 by aosp/1679887. Fragments now correctly handle transition groups (either set directly via transitionGroup="true" or indirectly via a transitionName or background) and shared elements will no longer throw IndexOutOfBoundsExceptions. (I16484, b/188679569, b/188969304)

关于android - 共享元素过渡到包含 ViewPager 的 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67892984/

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