请注意问题底部的编辑
我有两项活动:ActivityA
,ActivityB
,分别包含相关联的条件:FragmentA
,FragmentB
。这两个片段之间共享ImageView v
。
一些代码: ActivityA
Intent intent = new Intent(this, ActivityB.class);
final ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.
makeSceneTransitionAnimation(this, imageView, "photo");
ActivityCompat.startActivity(this, intent, activityOptionsCompat.toBundle());
ActivityB
FragmentB fragment = new FragmentB();
getFragmentManager().beginTransaction()..replace(R.id.fragment_container, fragment, TAG).addToBackStack(TAG).commit();
FragmentB
mView = (ImageView) view.findViewById(R.id.view);
ViewCompat.setTransitionName(mView, "photo);
5次中有4次正在工作。但是当它无法正常工作时,我会收到非常有用的错误:
W/OpenGLRenderer﹕ Layer exceeds max. dimensions supported by the GPU (1080x10659, max=4096x4096)
JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception 'java.lang.IllegalStateException' thrown in void android.os.MessageQueue.nativePollOnce(long, int):-2
致电Picasso
Picasso.with(context).load(url).centerCrop().resize(width, height).noFade().into(mView);
可能导致这种情况的事情很少:
FragmentB
mView
位置的是使用ViewTreeObserver.OnGlobalLayoutListener
动态计算的
mView
扩展ImageView
以便在两个片段中创建椭圆效果。
ViewGroup
是ScrollView
最后一件事:两个活动的Theme
都是
<style name="Theme" parent="Theme.AppCompat.Light"
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>
---编辑---
Similar question and answer to my problem and another
答案可以解决问题,但仅适用于 API 21 。我正在使用ActivityCompat.startActivity(...)
。它支持 api 16 以及,但 TransitionListener
仅在 API 19 后可用,并支持SceneTransition
,因为 API 21
同样android:transitionGroup="true"
需要API 21
所以现在我有 2个主要问题:
LayerExceeds max
错误?我的共享View
不大于1080x1080。 TransitionListener
和transitionGroup
都不可用?错误堆栈跟踪
JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception 'java.lang.IllegalStateException' thrown in void android.os.MessageQueue.nativePollOnce(long, int):-2
in call to CallVoidMethodV
art/runtime/check_jni.cc:65] from void android.os.MessageQueue.nativePollOnce(long, int)
art/runtime/check_jni.cc:65] "main" prio=5 tid=1 Runnable
art/runtime/check_jni.cc:65] | group="main" sCount=0 dsCount=0 obj=0x72fb6000 self=0xb4827800
art/runtime/check_jni.cc:65] | sysTid=6497 nice=0 cgrp=default sched=0/0 handle=0xb6f83bec
art/runtime/check_jni.cc:65] | state=R schedstat=( 1181860917 459124594 2277 ) utm=100 stm=18 core=2 HZ=100
art/runtime/check_jni.cc:65] | stack=0xbe27d000-0xbe27f000 stackSize=8MB
art/runtime/check_jni.cc:65] | held mutexes= "mutator lock"(shared held)
art/runtime/check_jni.cc:65] native: #00 pc 00004e64 /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
art/runtime/check_jni.cc:65] native: #01 pc 00003665 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8)
art/runtime/check_jni.cc:65] native: #02 pc 00256429 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+84)
art/runtime/check_jni.cc:65] native: #03 pc 00238fe7 /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+158)
art/runtime/check_jni.cc:65] native: #04 pc 000b191b /system/lib/libart.so (art::JniAbort(char const*, char const*)+610)
art/runtime/check_jni.cc:65] native: #05 pc 000b2055 /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+68)
art/runtime/check_jni.cc:65] native: #06 pc 000b530f /system/lib/libart.so (art::ScopedCheck::ScopedCheck(_JNIEnv*, int, char const*)+1346)
art/runtime/check_jni.cc:65] native: #07 pc 000bd6f7 /system/lib/libart.so (art::CheckJNI::CallVoidMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::__va_list)+42)
art/runtime/check_jni.cc:65] native: #08 pc 0006244b /system/lib/libandroid_runtime.so (???)
art/runtime/check_jni.cc:65] native: #09 pc 000760c5 /system/lib/libandroid_runtime.so (android::NativeDisplayEventReceiver::dispatchVsync(long long, int, unsigned int)+40)
native: #10 pc 0007628d /system/lib/libandroid_runtime.so (android::NativeDisplayEventReceiver::handleEvent(int, int, void*)+80)
native: #11 pc 00012545 /system/lib/libutils.so (android::Looper::pollInner(int)+484)
native: #12 pc 000125ed /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+92)
native: #13 pc 00081709 /system/lib/libandroid_runtime.so (android::NativeMessageQueue::pollOnce(_JNIEnv*, int)+22)
native: #14 pc 000b3863 /data/dalvik-cache/arm/system@framework@boot.oat (Java_android_os_MessageQueue_nativePollOnce__JI+102)
at android.os.MessageQueue.nativePollOnce(Native method)
at android.os.MessageQueue.next(MessageQueue.java:143)
at android.os.Looper.loop(Looper.java:122)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke!(Native method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Fatal signal 11 (SIGSEGV), code 1, fault addr 0xfffffff0 in tid 6497
答案 0 :(得分:2)
您链接的第二个问题的accepted answer讨论了发生这种情况的原因:大小限制是在整个预渲染目标Activity上,而不仅仅是转换后的元素。将android:transitionGroup="true"
添加到转换布局中的适当位置将修复崩溃。你没有在问题中发布你的布局,所以很难知道它会发生什么,但如果你有一个ScrollView
或其他非常长的视图,那将是一个很好的起点。
对于21之前的API级别,这不是问题。 AppCompat.startActivity()
将在21级以下的API级别上运行,但共享元素转换动画将无法运行。它将回退到默认的活动转换。