【问题标题】:Android animation of image view moving and rotating图像视图移动和旋转的Android动画
【发布时间】:2015-02-06 22:43:23
【问题描述】:

我想制作一个动画,将图像视图从屏幕的开头移动到结尾,并且每次都随机化 x 位置。我怎么能这样做?

 <set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator" >

<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="359"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="1000"
    android:repeatCount="infinite"
    />
<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0%"
    android:fromYDelta="0%"
    android:toYDelta="100%"
    android:repeatCount="infinite"
    android:duration="3000"
    ></translate>
    </set>

我不知道如何随机化 X 坐标,以及为什么即使我使用了 0% 和 100%,它并没有真正从屏幕的开头开始,也没有在结尾结束。 提前感谢您的帮助!

【问题讨论】:

    标签: android xml animation rotation imageview


    【解决方案1】:

    要使动画从父 [p] 对象的最顶部(y 轴)部分开始并在默认位置结束,即如果它没有动画时的位置,请修改您的翻译定义如下:

    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromYDelta="-100%p"
        android:toYDelta="0"
        android:repeatCount="infinite"
        android:duration="3000">
        </translate>
    

    如果您更喜欢从底部开始的动画,请使用:android:fromYDelta="100%p"

    关于第二个问题,您可以使用属性android:interpolator 来定义动画的节奏。

    例如:

     androd:interpolator="@android:anim/bounce_interpolator"
    

    Here is a short video 演示每个插值器的效果。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-09
      • 1970-01-01
      • 2014-01-05
      • 1970-01-01
      相关资源
      最近更新 更多