android
natively has no resource for .gif
animated.
For you to do this effect we will have to have all the images of the animation available to be added in a xml
.
Then create an xml named animation.xml
and add this content to it:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
id="animacao" android:oneshot="false" >
<item android:drawable="@drawable/android1" android:duration="150" />
<item android:drawable="@drawable/android2" android:duration="150" />
<item android:drawable="@drawable/android3" android:duration="150" />
<item android:drawable="@drawable/android4" android:duration="150" />
<item android:drawable="@drawable/android5" android:duration="150" />
<item android:drawable="@drawable/android6" android:duration="150" />
<item android:drawable="@drawable/android7" android:duration="150" />
</animation-list>
And in the xml of your Activity
create a ImageView
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/imgAndroid"
android:background="@drawable/android1"
android:layout_gravity="center_horizontal" />
Now in your Activity class, link ImageView
and create AnimationDrawable
by implementing your class this way:
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class Main extends Activity {
private ImageView imgAndroid;
private AnimationDrawable mAnimation;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imgAndroid = (ImageView)findViewById(R.id.imgAndroid);
imgAndroid.setBackgroundResource(R.drawable.animation);
mAnimation = (AnimationDrawable)imgAndroid.getBackground();
mAnimation.start();
}
}
And to stop the animation use: mAnimation.stop();