使用共享元素的过渡与ChangeImageTransform两种活动之间的动画的ImageView [英] Animate ImageView between two activities using shared element transitions with ChangeImageTransform

查看:2868
本文介绍了使用共享元素的过渡与ChangeImageTransform两种活动之间的动画的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个ImageView的动画在Android的大号preVIEW在Android的API级别21的两项活动之间的另一个位置。由于MoveImage已被删除,我用<一href="https://developer.android.com/reference/android/transition/ChangeImageTransform.html">ChangeImageTransform"相反,但样本code。在文件不工作(分别动画两个图像)。

 &LT; transitionSet的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android&GT;
    &LT; changeImageTransform&GT;
        &LT;目标&GT;
            &lt;目标机器人:目标=@ ID / IVA/&GT;
            &lt;目标机器人:目标=@ ID / IVB/&GT;
        &LT; /目标&GT;
    &LT; / changeImageTransform&GT;
&LT; / transitionSet&GT;
 

有没有工作的例子吗?谢谢!

解决方案

要进行两次活动有一个共同的元素之间的屏幕过渡动画, 你可以阅读这篇文章,并按照提到的步骤:

  
      
  1. 打开窗口的内容转换在你的主题。
  2.   
  3. 指定在样式共享元素的过渡。
  4.   
  5. 定义您的转换为XML的资源。
  6.   
  7. 分配一个共同的名字在这两个布局的Andr​​oid共享的元素:transitionName属性
  8.   
  9. 使用ActivityOptions.makeSceneTransitionAnimation()方法。
  10.   

关于第三步骤,根据本<一href="https://developer.android.com/reference/android/transition/ChangeImageTransform.html">documentation:

  

在与ChangeBounds组合,ChangeImageTransform允许改变大小,形状或ImageView.ScaleType流畅的动画内容ImageViews。

在RES /转换/ your_transition.xml应该是这样的:

 &LT; transitionSet的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android&GT;
    &LT; changeBounds&GT;
        &LT;目标&GT;
            &lt;目标机器人:目标=@ ID / IVA/&GT;
            &lt;目标机器人:目标=@ ID / IVB/&GT;
        &LT; /目标&GT;
    &LT; / changeBounds&GT;
    &LT; changeImageTransform&GT;
        &LT;目标&GT;
            &lt;目标机器人:目标=@ ID / IVA/&GT;
            &lt;目标机器人:目标=@ ID / IVB/&GT;
        &LT; /目标&GT;
    &LT; / changeImageTransform&GT;
&LT; / transitionSet&GT;
 

或者干脆像这样如果只IVA和IVB需要被激活:

 &LT; transitionSet的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android&GT;
    &LT; changeBounds /&GT;
    &LT; changeImageTransform /&GT;
&LT; / transitionSet&GT;
 

I am trying to animate one ImageView to another position between two activities in Android API level 21. Since "MoveImage" in Android L Preview has been removed, I use "ChangeImageTransform" instead, but the sample code in documents doesn't work out (the two images animated separately).

<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    <changeImageTransform>
        <targets>
            <target android:targetId="@id/ivA" />
            <target android:targetId="@id/ivB" />
        </targets>
    </changeImageTransform>
</transitionSet>

Is there any working example? Thanks!

解决方案

To make a screen transition animation between two activities that have a shared element, you can read this article and follow the mentioned steps:

  1. Enable window content transitions in your theme.
  2. Specify a shared elements transition in your style.
  3. Define your transition as an XML resource.
  4. Assign a common name to the shared elements in both layouts with the android:transitionName attribute.
  5. Use the ActivityOptions.makeSceneTransitionAnimation() method.

About the 3rd step, according to the documentation:

In combination with ChangeBounds, ChangeImageTransform allows ImageViews that change size, shape, or ImageView.ScaleType to animate contents smoothly.

The res/transition/your_transition.xml should be like this:

<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    <changeBounds>
        <targets>
            <target android:targetId="@id/ivA" />
            <target android:targetId="@id/ivB" />
        </targets>
    </changeBounds>
    <changeImageTransform>
        <targets>
            <target android:targetId="@id/ivA" />
            <target android:targetId="@id/ivB" />
        </targets>
    </changeImageTransform>
</transitionSet>

or simply like this if only ivA and ivB need to be animated:

<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    <changeBounds/>
    <changeImageTransform/>
</transitionSet>

这篇关于使用共享元素的过渡与ChangeImageTransform两种活动之间的动画的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆