Best Way To Animate Images Frame By Frame In Android
Solution 1:
Do this way..
---------------------
ImageView img = (ImageView)findViewById(R.id.some layout);
AnimationDrawable frameAnimation = (AnimationDrawable)img.getDrawable();
frameAnimation.setCallback(img);
frameAnimation.setVisible(true, true);
frameAnimation.start();
and to add animation you can do something like
-----------------------------------------------
<animation-list android:id="@+id/my_animation" android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/frame1" android:duration="150" />
<item android:drawable="@drawable/frame2" android:duration="150" />
</animation-list>
Solution 2:
After looking into several posts and doing much research, I finally ended up modifying the images in Imageview programmatically to simulate frame animation. That way I am just maintaining three images in cache at any point of time (previous, current and next one). I hope that this will be useful to others.
Solution 3:
It is not a good thing to process a large amount of images in a frame like manner in Android itself as it will trigger the dreaded "Out of Memory" exception.
Clearing the memory itself is not possible. The best fix for this is proper bitmap handling of the app.
I'm not sure but you might want to check on PhoneGap.
Its an HTML5 Engine that we used before to create a game. By drawing into the canvas itself, we've recreated frame animation with it. It just requires WebDev skills though.
Post a Comment for "Best Way To Animate Images Frame By Frame In Android"