Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animating an Image with ImageView

I'm pretty new to Android programming, and I've looked around but haven't been able to find a clear-cut answer. I need to slowly animate an image by switching it with anothe, like a sprite. If anyone can help, it seems like it should be really simple. Thanks!

like image 550
Jack Avatar asked Nov 01 '11 21:11

Jack


People also ask

How do I animate an image in Xcode?

Once you have your folder with all your images, go to Xcode, select your project assets catalog, and drag-and-drop the animation folder. To make sure everything stay organized, enable the "Provide Namespace" option. It will make assets accessible from "FolderName/ImageName" instead of "ImageName" in your swift files.

How to change image with animation Swift?

Animating an image change with Swift is quite simple, all we need to do is use UIView. transition . To do this I have created a new project and added a UIImageView to my Main.

How to animate a drawable in Android?

One way to animate Drawables is to load a series of Drawable resources one after another to create an animation. This is a traditional animation in the sense that it is created with a sequence of different images, played in order, like a roll of film. The AnimationDrawable class is the basis for Drawable animations.


1 Answers

You'll probably want to use a TransitionDrawable http://developer.android.com/reference/android/graphics/drawable/TransitionDrawable.html

Drawable[] layers = new Drawable[2];
layers[0] = //your first drawable
layers[1] = //your second drawable
TransitionDrawable transition = new TransitionDrawable(layers);
myImageView.setImageDrawable(transition);
transition.startTransition(1500);
like image 53
Damian Avatar answered Sep 17 '22 16:09

Damian