如何在android中制作平滑的帧动画? [英] How to make smooth frame animation in android?

查看:37
本文介绍了如何在android中制作平滑的帧动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个帧动画.但是图像之间的过渡看起来很糟糕.如何对其应用交叉淡入淡出效果?

I made a frame animation. But the transitition between images is bad looking. How can I apply a crossfade effect to it ?

当使用 TransitionDrawable 时,我得到了正确的结果,但它在一次执行后停止.

When using TransitionDrawable i get the proper result but it stops after one execution.

有人知道如何解决吗?

public void startAnimation() {
    if (logoAnimation != null) {
        if (logoAnimation.isRunning()) {
            logoAnimation.stop();
        }
        logoAnimation.start();
    }
}

private int setLogoAnimation(int animationID, int targetID) {
    imageView = (ImageView) window.findViewById(targetID);
    imageView.setImageResource(animationID);
    logoAnimation = (AnimationDrawable) imageView.getDrawable();

    if (imageView != null && logoAnimation != null) {
        return 1;
    } else {
        return 0;
    }
}

比我简单地通过 object.startAnimation(); 运行它我可以工作,但动画很难看,我需要它流畅.

Than I simply run it by object.startAnimation(); I works, but the animation is ugly and I need it to be smooth.

推荐答案

如果你想在两张图片之间交叉淡入淡出,为什么不使用 AlphaAnimation 来改变两个视图的透明度并创建你需要的效果.

If you want to crossfade between two pictures, why not use an AlphaAnimation which will alter the transparency of two views and will create the effect that you require.

p>

创建两个动画:

Create two animations:

res/anim/fadeout.xml

res/anim/fadeout.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromAlpha="1.0" android:toAlpha="0.0"
    android:duration="@android:integer/config_mediumAnimTime" />

res/anim/fadein.xml

res/anim/fadein.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromAlpha="0.0" android:toAlpha="1.0"
    android:duration="@android:integer/config_mediumAnimTime" />

然后覆盖activity之间的默认过渡:

and then override the default transition between activities:

startActivity( new Intent( this, SecondActivity.class ) );
overridePendingTransition( R.anim.fadeout, R.anim.fadein );

或者您可以将动画应用到特定的小部件:

or you can apply animations to specific widgets:

Animation animation = AnimationUtils.loadAnimation( this, R.anim.fadeout );
image1.startAnimation( animation );

我目前正在我的博客上制作一系列动画,这可能会给你一些进一步的信息.

I am currently in the middle of a series on animation on my blog which may give you some further information.

这篇关于如何在android中制作平滑的帧动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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