我做了一个帧动画。但是图像之间的过渡很糟糕。如何对其应用交叉渐变效果?
使用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()运行它;我工作,但动画很难看,我需要它很流畅。
答案 0 :(得分:7)
如果你想在两张图片之间交叉淡入淡出,为什么不使用AlphaAnimation来改变两个视图的透明度,并创建你需要的效果。
创建两个动画:
RES /动画/ 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
<?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" />
然后覆盖活动之间的默认转换:
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动画系列的中间,可能会为您提供更多信息。
答案 1 :(得分:0)
通过使用帧动画增加帧数可以帮助您获得良好的结果。在我的情况下,我的HTC Evo结果令人满意。
使用补间动画时,您可以使用线性插值器。例如旋转
<?xml version="1.0" encoding="UTF-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="359"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:duration="1000"
android:interpolator="@anim/linear_interpolator" />
你在这里插入文件内容
<?xml version="1.0" encoding="utf-8"?>
<linearInterpolator xmlns:android="http://schemas.android.com/apk/res/android" />
这是轮换,您可以在此处查看完整列表。
http://developer.android.com/guide/topics/resources/animation-resource.html
或者你可以阅读我写的如何制作加载动画的博客文章。
http://yekmer.posterous.com/how-to-make-a-loading-animator-in-android