我做了一个帧动画。但是图像之间的过渡看起来很糟糕。我如何对其应用交叉淡入淡出效果?
当使用TransitionDrawable
时,我得到了正确的结果,但是在执行一次后停止了。
有人知道如何解决吗?
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();来简单地运行它我可以工作,但是动画很难看,我需要使其流畅。
最佳答案
如果要在两张图片之间进行淡入淡出,为什么不使用AlphaAnimation会改变两个 View 的透明度并创建所需的效果。
创建两个动画:
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
<?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 之间的默认过渡:
startActivity( new Intent( this, SecondActivity.class ) );
overridePendingTransition( R.anim.fadeout, R.anim.fadein );
或者您可以将动画应用于特定的小部件:
Animation animation = AnimationUtils.loadAnimation( this, R.anim.fadeout );
image1.startAnimation( animation );
我目前正在blog上进行动画制作,这可能会给您一些进一步的信息。
关于android - 如何在Android中制作平滑的帧动画?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5880559/