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中制作平滑的帧动画?


- android 4中的android RadioButton问题 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01