简单的补间动画的例子

简单的补间动画的例子

本文介绍了简单的补间动画的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实施超空间补间动画的http://developer.android.com/guide/topics/resources/animation-resource.html (动漫资源) - 但它似乎没有工作作为编写的。当我运行的应用程序,我只是得到下面的应用程序标题栏空白视图。我究竟做错了什么?

I'm trying to implement the "hyperspace" tween animation described at http://developer.android.com/guide/topics/resources/animation-resource.html ("Animation Resources") - however it does not seem to work as written. When I run the application, I just get a blank view below the application title bar. What am I doing wrong?

%的例子,这里是我的code。我创建RES /动画/ hyperspace_jump.xml:

Per the example, here is my code. I've created res/anim/hyperspace_jump.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <scale
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="1.0"
        android:toXScale="1.4"
        android:fromYScale="1.0"
        android:toYScale="0.6"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false"
        android:duration="700" />
    <set
        android:interpolator="@android:anim/accelerate_interpolator"
        android:startOffset="700">
        <scale
            android:fromXScale="1.4"
            android:toXScale="0.0"
            android:fromYScale="0.6"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="400" />
        <rotate
            android:fromDegrees="0"
            android:toDegrees="-45"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="400" />
    </set>
</set>

我还创建了一个布局/ main.xml中:

I've also created a layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>

</LinearLayout>

最后,我有一个活动:

Finally I have an activity:

package com.tomoreilly.geology;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageView image = (ImageView) findViewById(R.id.ImageView01);
        Animation hyperspaceJump =
            AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
        image.startAnimation(hyperspaceJump);
    }
}

不过,我没有看到任何动画,当我运行的应用程序。我缺少一些细节未包括在动漫资源的例子?

Yet I do not see any animation when I run the app. Am I missing some detail that is not covered in the "Animation Resources" example?

谢谢,汤姆

推荐答案

要添加不同的答案,你也可以试试通用吐温引擎动画你的android用户界面。事实上,动画,这就要求在其XML格式好几行,会是这样描述的:

To add a different answer, you could also try the Universal Tween Engine to animate your android UIs. Indeed, your animation, which requires quite a few lines in its XML format, would be described like this:

Timeline.createSequence()
    // First, set your pivot (Tween.set() works instantly)
    .push(Tween.set(image, ViewAccessor.PIVOT_XY).target(0.5f, 0.5f))

    // Then, animate your scale and rotation as you want
    .push(Tween.to(image, ViewAccessor.SCALE_XY, 0.7f).target(1.4f, 0.6f))
    .beginParallel()
        .push(Tween.to(image, ViewAccessor.SCALE_XY, 0.4f).target(0, 0))
        .push(Tween.to(image, ViewAccessor.ROTATION, 0.4f).target(-45))
    .end()

    // Finally, start the animation!
    .start();

当你有一个大组动作序列,这可能是更具可读性。发动机在很大程度上对机器人进行了优化,尤其是对游戏,并且不分配任何东西,以提供最佳的性能。

It may be more readable when you have a big set of actions to sequence. The engine is heavily optimized for android, and especially for games, and doesn't allocate anything, to provide the best performance.

这是完全开源的,重记录,并发布了与Apache 2许可证。

It is completely open-source, heavily documented, and released with an Apache-2 license.

您可以给的Andr​​oid演示一试,如果你想:)

You can give the Android demo a try if you want :)

这篇关于简单的补间动画的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 13:04