我在使用Android Transition
API时遇到了一个非常奇怪的问题。我有sharedElement
一个ImageView
,我让操作系统处理Transition
这两个元素之间。但是我有这个奇怪的问题,如下面的gif所示
如您所见,element
我animating
是唯一的AvatarView
,但是onBackPressed
使用此日志使应用程序崩溃
java.lang.IllegalStateException: Unable to create layer for CardView
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
开始的代码 Activity
第一的 Layout
<com.fastaccess.ui.widgets.AvatarLayout
android:id="@+id/avatarLayout"
android:layout_width="48dp"
android:layout_height="48dp"
android:transitionName="@string/image_transition"/>
第二 Layout
<com.fastaccess.ui.widgets.AvatarLayout
android:id="@+id/avatarLayout"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="top"
android:transitionName="@string/image_transition"/>
这就是我开始的方式 Transition
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
sharedElement, ViewHelper.getTransitionName(sharedElement));
activity.startActivity(intent, options.toBundle());
此后没有多余的代码,除了我打电话 supportFinishAfterTransition
这是另一个gif,但没有SharedElement Transition
&则可以正常工作。
To be honest the Crash log does not tell much, but i can confirm its due to the Comment TextView
is being Large even tho it has nothing to do with the SharedElement
but it seems it is the cause to the Crash as per my tests.
It'll be great if anyone has encounter this before and found a way to fix it as i gave up.
Any suggestions will be appreciated.
First Fix Attempting:
setting android:transitionGroup="false"
on the RowItem
rootLayout
itself as if i did set it on the ViewPager
or on the RecyclerView
the same crash will happen.Another important step was returning false
on hasOverlappingRendering()
from the custom TextView
class. but this causes the ExitTransition
to have a flickery background color Another Weird issue I'll be digging more on this & won't accept this answer until i find a solution to the flickery background or someone else has a different approach to fix this.
Edit
The weird background is actually the CardView
itself that holds the CommentTextView
.
Edit
实际上,这CardView
是真正的原因,而且时间不长,TextView
我将CardView更改LinearLayout
为我的行项目的根元素,并删除了我在上面所做的所有变通办法,并且一切似乎都正常进行。我不知道为什么会导致此问题,我希望有人可以提供帮助并详细说明为什么大型CardView
问题会导致此问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句