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:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
