Tuesday, 10 December 2013

Android Animation

Click here to acess pdf of this POST Lionel® - Shop Trains Shop the Lionel Online Store Today. 10% off All Orders With Promo Code CJN10P. package com.sawan;

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

public class HelloAnimationActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
Button start,stop;
AnimationDrawable animationDrawable=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        start= (Button) findViewById(R.id.button1);
        stop=(Button) findViewById(R.id.button2);
        start.setOnClickListener(this);
        stop.setOnClickListener(this);
    }
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button1:
startanimation();
break;
case R.id.button2:
stopanimation();
default:
break;
}
}
private void stopanimation() {
// TODO Auto-generated method stub
animationDrawable.stop();
}
private void startanimation() {
// TODO Auto-generated method stub
ImageView img=(ImageView) findViewById(R.id.imageView1);
BitmapDrawable image1=(BitmapDrawable) getResources().getDrawable(R.drawable.splash1);
BitmapDrawable image2=(BitmapDrawable) getResources().getDrawable(R.drawable.splash2);
BitmapDrawable image3=(BitmapDrawable) getResources().getDrawable(R.drawable.splash3);

int resonableduration=500;
animationDrawable=new AnimationDrawable();
animationDrawable.addFrame(image1, resonableduration);
animationDrawable.addFrame(image2, resonableduration);
animationDrawable.addFrame(image3, resonableduration);

img.setBackgroundDrawable(animationDrawable);
animationDrawable.setVisible(true,true);
animationDrawable.start();




}
}

Download
click to begin
1.2MB .zip

No comments:

Post a Comment