我跟着这个Android开发博客文章 https://android-developers.googleblog.com/2018/02/continuous-shared-element-transitions.html,这是他的源代码 https://github.com/android/animation-samples/tree/master/GridToPager.
该演示运行良好,但通常我们更喜欢使用centerCrop
图像列表中的比例类型,并使用fitCenter
在详细模式下。当我修改代码来实现这一点时,转换无法处理比例类型的变化。从细节片段返回时,动画以错误的比例类型开始。
我找到了ChangeImageTransform https://developer.android.com/reference/android/transition/ChangeImageTransform过渡。该文件说:
此转换在场景更改之前和之后捕获 ImageView 的矩阵,并在转换期间为其设置动画。
与 ChangeBounds 结合使用,ChangeImageTransform 允许 ImageView 更改大小、形状或ImageView.ScaleType顺利地制作动画内容。
所以我改变了过渡集:
<transitionSet
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="375"
android:interpolator="@android:interpolator/fast_out_slow_in"
android:transitionOrdering="together">
<changeBounds/>
<changeImageTransform/>
</transitionSet>
但动画变得越来越丑陋:
不同尺度类型之间如何平滑转换?
我关注了同一个项目网格转页器 https://github.com/android/animation-samples/tree/master/GridToPager并面临着确切的问题。这里有两个改变可以达到目的。
image_shared_element_transition.xml
<?xml version="1.0" encoding="utf-8"?>
<transitionSet
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="375"
android:interpolator="@android:interpolator/fast_out_slow_in"
android:transitionOrdering="together">
<changeClipBounds/>
<changeTransform/>
<changeBounds/>
<changeImageTransform/>
</transitionSet>
and
Remove android:clipChildren="false"
image_card.xml 中 CardView 的属性
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)