首页 > 解决方案 > 棉花糖和奥利奥中的共享元素有不同的结果

问题描述

我想通过共享元素在聊天活动中制作一个浏览喜欢微信的图片的活动。但我发现了。使用相同的代码,动画在我的第一部手机(Android 6.0)中非常流畅。而在第二部手机(Android 8.0)中,动画有点不流畅。你有没有遇到过这样的情况?你知道原因吗?任何解决方案?

标签: androidshared-element-transition

解决方案


我在我的演示中发现,如果你的活动如下

getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.changebounds_with_test))

你的过渡如下

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500">
    <changeBounds/>
    <changeImageTransform/>
    <changeClipBounds/>
    <changeTransform/>
</transitionSet>

重点是持续时间大于 300 毫秒(默认持续时间)。那么Shared Element的动画在Oreo中就不流畅了。但是我没有在我的项目中设置 SharedElementEnterTransition,动画在 Oreo 中也很不流畅。我认为我的项目有任何影响动画的代码逻辑,这导致持续时间大于 300 毫秒。现在我不使用共享元素,而是使用值动画来制作过渡动画。


推荐阅读