Animation

Animation (Frame by Frame Demo)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<Button android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:id="@+id/Button1"
		android:text="Start" />
	<ImageView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:id="@+id/ImageView1" />
</LinearLayout>

/res/drwable/spin_animation.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/a" android:duration="500"/>
    <item android:drawable="@drawable/b" android:duration="500"/>
    <item android:drawable="@drawable/c" android:duration="500"/>
</animation-list>

/res/drawalbe/a.png
/res/drawalbe/b.png
/res/drawalbe/c.png

Activity file

package com.androidwork.animationdemo;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class AnimationDemoActivity extends Activity {
    /** Called when the activity is first created. */
	 AnimationDrawable animation;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button b = (Button) findViewById(R.id.Button1);
        b.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ImageView iv = (ImageView) findViewById(R.id.ImageView1);
				iv.setBackgroundResource(R.drawable.spin_animation);
				AnimationDrawable ad = (AnimationDrawable) iv.getBackground();
				ad.start();
			}
		});
    }
  }

Output

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s