如何使流畅的帧动画的android? [英] How to make smooth frame animation in android?
问题描述
我做了一个帧动画。但图像之间的transitition是难看。如何申请交叉淡入淡出的效果呢?
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.
任何人有一个想法如何解决这个问题?
Any one has an idea how to resolve it?
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.
创建两个动画:
RES /动画/ 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 /动画/ 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" />
,然后覆盖活动之间的默认过渡:
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屋!