How to make smooth frame animation in android?(如何在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中制作平滑的帧动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在android中制作平滑的帧动画?
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01