How to make smooth frame animation in android?

流过昼夜 提交于 2019-12-03 08:58:46
Mark Allison

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.

Create two animations:

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" />

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.

By using frame animation increasing frame number can help you to get a good result. In my case the result was satisfactory on my HTC Evo.

While using tween animation you can use linear interpolator. For rotation for example

<?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" />  

And you interpolator file content here

<?xml version="1.0" encoding="utf-8"?>
<linearInterpolator xmlns:android="http://schemas.android.com/apk/res/android" />

This is for rotation, you can see full list here.

http://developer.android.com/guide/topics/resources/animation-resource.html

or you can read a blog post that I write how to make a loading animation.

http://yekmer.posterous.com/how-to-make-a-loading-animator-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!