gpt4 book ai didi

android - 运行 Android 8.0 的三星设备上的共享元素转换崩溃

转载 作者:行者123 更新时间:2023-11-30 05:12:49 26 4
gpt4 key购买 nike

我遇到了一个奇怪的崩溃,显然无法修复发生在仅运行 Android 8.0 的三星设备上。

我在 Fragment 中填充了一个 recyclerView,它正在启动一个 Activity。

这是我的 ItemHolder 布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="@dimen/table_card_header_size"
android:transitionName="@string/team_profile_transition"
android:id="@+id/tableRowMainContainer"
android:background="@drawable/rounded_rect_top"
> ...

这是我对具有共享元素的 Activity 的 Intent

private val teamProfileOnClick = View.OnClickListener { v ->
val teamContainer = v.findViewById<FrameLayout>(R.id.tableRowMainContainer)
val tag = v.tag as TableRow
val intent = Intent(context, TeamProfileActivity::class.java)
intent.putExtra(TeamProfileActivity.TEAM_ID_PROFILE, tag.teamId)
intent.putExtra(TeamProfileActivity.TEAM_NAME, tag.team.name)
intent.putExtra(TeamProfileActivity.TEAM_COMPETITION_ID, tableCompetitionId)
intent.putExtra(TeamProfileActivity.TEAM_TYPE, tag.team.teamType)

val options = ActivityOptionsCompat.makeSceneTransitionAnimation(context as Activity,
teamContainer,
ViewCompat.getTransitionName(teamContainer))
context.startActivity(intent, options.toBundle())
}

这是目标 Activity 的布局

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tool="http://schemas.android.com/tools"
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:transitionName="@string/team_profile_transition"
app:cardCornerRadius="10dp"
> ...

这是崩溃日志

java.lang.NullPointerException: 
at android.app.ActivityTransitionCoordinator.setSharedElementState (ActivityTransitionCoordinator.java:553)
at android.app.ActivityTransitionCoordinator.setSharedElementState (ActivityTransitionCoordinator.java:653)
at android.app.EnterTransitionCoordinator.startSharedElementTransition (EnterTransitionCoordinator.java:428)
at android.app.EnterTransitionCoordinator.-wrap4 (Unknown Source)
at android.app.EnterTransitionCoordinator$3.lambda$-android_app_EnterTransitionCoordinator$3_18867 (EnterTransitionCoordinator.java:492)
at android.app.-$Lambda$CsyQO--8YdRe5wlajUCi-L98enA$1.$m$0 (Unknown Source:8)
at android.app.-$Lambda$CsyQO--8YdRe5wlajUCi-L98enA$1.run (Unknown Source)
at android.app.ActivityTransitionCoordinator.startTransition (ActivityTransitionCoordinator.java:902)
at android.app.EnterTransitionCoordinator$3.lambda$-android_app_EnterTransitionCoordinator$3_18819 (EnterTransitionCoordinator.java:491)
at android.app.-$Lambda$CsyQO--8YdRe5wlajUCi-L98enA$2.$m$0 (Unknown Source:8)
at android.app.-$Lambda$CsyQO--8YdRe5wlajUCi-L98enA$2.run (Unknown Source)
at com.android.internal.view.OneShotPreDrawListener.onPreDraw (OneShotPreDrawListener.java:78)
at android.view.ViewTreeObserver.dispatchOnPreDraw (ViewTreeObserver.java:1045)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2800)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1779)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:7810)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:911)
at android.view.Choreographer.doCallbacks (Choreographer.java:723)
at android.view.Choreographer.doFrame (Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:897)
at android.os.Handler.handleCallback (Handler.java:789)
at android.os.Handler.dispatchMessage (Handler.java:98)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6938)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

最佳答案

我找到的解决方案如下:打开共享元素时卡住/解冻 recyclerView :

 override fun onPause() {
super.onPause()
tableCardStack.isLayoutFrozen = true
}

override fun onResume() {
super.onResume()
tableCardStack.isLayoutFrozen = false
}

我注意到我正在设置动画的 View 没有动画回到正确的位置。所以我想卡住布局。我知道这不是最好的解决方案,但我找不到更好的解决方案

关于android - 运行 Android 8.0 的三星设备上的共享元素转换崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53450609/

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