繁体   English   中英

在Android中使用视图动画

[英]Using view animations in Android

考虑我有类似的东西:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
>
    <rotate
    android:fromDegrees="0"
    android:toDegrees="10"
    android:duration="200" >

    <rotate
    android:fromDegrees="20"
    android:toDegrees="0"
    android:startOffset="200"
    android:duration="200" 
    android:fillBefore="false" 
    android:fillEnabled="true">
</set>

在这里,我希望在200 ms时间后应用第二次旋转(第一次旋转的最终结果)。 但是结果是,我看到甚至在200 ms之前就应用了android:fromDegrees(第二次旋转),因为前200毫秒默认为20度旋转。 我希望整个程序块仅在200毫秒后生效。 我该如何克服呢?

也有任何经验法则可以理解android:fromDegrees,android:toDegrees,因为它可以采用负值以及0-20或20-0之类的值。 我们如何正确解释这些值?

提前致谢。

创建两个动画。 那是一个应该首先发生,另一个在200ms之后发生。 向第一个动画添加一个动画侦听器,当动画停止时它将调用onAnimationEnd方法,在该方法中,启动另一个动画

第一个动画文件

<rotate
android:fromDegrees="0"
android:toDegrees="10"
android:duration="200" >

第二动画文件

<rotate
android:fromDegrees="20"
android:toDegrees="0"
android:startOffset="200"
android:duration="200" 
android:fillBefore="false" 
android:fillEnabled="true">

设置:

anim.setAnimationListener(new AnimationListener() {
      public void onAnimationStart(Animation anim)
      {
      };
      public void onAnimationRepeat(Animation anim)
      {
      };
      public void onAnimationEnd(Animation anim)
      {
           layout.startAnimation(the second animation here);
      };
});   

编辑

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="true"
     android:fillAfter="true">

编辑2:默认情况下,设置顺序会together更改为sequentially并检查动画

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="true"
     android:fillAfter="true"
   android:ordering="sequentially">

我已经发现问题中的代码片段表现出与我期望的完全一样的效果,并且只有一个不需要的结果。 实际上,第二轮旋转仅在完成第一轮旋转之后才开始。 这里的问题是:

android:fromDegrees="20"

将第二个旋转块中的结果应用于第一个旋转的最终结果。 如果您希望几何图形从20度旋转到0度,那应该发生什么。 由于我想使用第一个旋转程序段的最终结果,因此我替换了

android:fromDegrees="20"
android:toDegrees="0"

android:fromDegrees="0"
android:toDegrees="-20"

因此,输出符合预期。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM