Skip to content
This repository has been archived by the owner. It is now read-only.
Branch: master
Find file History

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.

id title brief samplecode sdk
Frame Animation
This tutorial will show how to create a Frame Animation.
title url
Frame Animation


  1. Create a new Xamarin.Android project named FrameAnimation.

  2. Copy the images to be animated into the Resource/Drawable directory. In the Properties window, each image should have its build action set to AndroidResource.

  3. Create an new resource file Resource/Anim/animate_android.xml to hold the animation list:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="" android:oneshot="false">
  <item android:drawable="@drawable/android_1"
        android:duration="100" />
  <item android:drawable="@drawable/android_2"
        android:duration="100" />
  <item android:drawable="@drawable/android_3"
        android:duration="100" />
  <item android:drawable="@drawable/android_4"
        android:duration="100" />
  <item android:drawable="@drawable/android_5"
        android:duration="100" />
  <item android:drawable="@drawable/android_6"
        android:duration="100" />
  <item android:drawable="@drawable/android_7"
        android:duration="100" />

The animation-list creates a list of images that are on Resources/Drawable that will be cycled through in the ImageView to cycle through as part of the animation.

  1. Open the file Resources/Layout/Main.axml and change the layout such that it has a single ImageView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
              android:orientation="vertical" >
  <ImageView android:id="@+id/animated_android"
  1. Open MainActivity.cs, and insert the following code for the OnCreate() method:
protected override void OnCreate(Bundle bundle){
  1. Now override the method OnWindowFocusChanged() in MainActivity.cs:
public override void OnWindowFocusChanged(bool hasFocus)
    if (hasFocus)
        ImageView imageView = FindViewById<ImageView>(Resource.Anim.animated_android);
        AnimationDrawable animation = (AnimationDrawable) imageView.Drawable;

The AnimationDrawable class is the basis for loading drawable resources one after another to create an animation. The drawable resources will be loaded one after another, according to the instructions in the resource file Resource/Anim/animate_android.xml. Notice that the animation is not started in OnCreate(), but in OnWindowFocusChanged(). This is because the AnimationDrawable has not been fully attached to the window. By starting the animation in OnWindowFocusChanged() the animation will start without any interaction when Android brings the window into focus.

  1. Run the application. You should see the word Android being animated similar to the following screen shots:

You can’t perform that action at this time.