,请注意问题底部的EDIT
我有2个 Activity :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());
Activity B
FragmentB fragment = new FragmentB();
getFragmentManager().beginTransaction()..replace(R.id.fragment_container, fragment, TAG).addToBackStack(TAG).commit();
片段B
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
call
Picasso
Picasso.with(context).load(url).centerCrop().resize(width, height).noFade().into(mView);
很少会导致此的事情:
使用
FragmentB
动态计算mView
中的ViewTreeObserver.OnGlobalLayoutListener
位置mView
扩展了ImageView
以便在两个片段中创建椭圆形效果。 ViewGroup
是ScrollView
最后一件事:这两个 Activity 的
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
回答确实可以解决问题,但仅适用于API21。我正在使用
ActivityCompat.startActivity(...)
。它支持api 16及以上版本,但 TransitionListener
仅从API 19开始可用,并且从api 21开始支持SceneTransition
android:transitionGroup="true"
也需要API 21
,所以现在我有 2个主要问题:LayerExceeds max
错误?我共享的View
不大于1080x1080。 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
最佳答案
您链接的第二个问题的accepted answer讨论了发生这种情况的原因:大小限制是在整个预渲染的目标Activity上,而不仅仅是过渡的元素。将android:transitionGroup="true"
添加到过渡版式中的适当位置将解决崩溃问题。您没有在问题中发布布局,因此很难知道该去哪里,但是如果您有ScrollView
或其他非常长的 View ,那将是一个很好的起点。
对于21之前的API级别,这不是问题。 AppCompat.startActivity()
将在低于21的API级别上运行,但是共享元素过渡动画将无法运行。它将退回到默认的 Activity 过渡。