Thursday, 6 September 2012

Introduction to Animation In Android

             Introduction to Animation In Android


AninmationdemoActivity.java



package a.b;

import android.app.Activity;
import android.os.Bundle;

public class AninmationdemoActivity extends Activity {

Myanimation anim;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        anim=new Myanimation(this);
        setContentView(anim);
    }
}




Myanimation .java


package a.b;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;

public class Myanimation extends View {
      Bitmap img,img1,img2,img3;
      float changey;
public Myanimation(Context context) {
super(context);
// TODO Auto-generated constructor stub
img=BitmapFactory.decodeResource(getResources(), R.drawable.r);
img1=BitmapFactory.decodeResource(getResources(), R.drawable.b);

changey = 0;
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(img, (canvas.getWidth()/2),changey,null);
canvas.drawBitmap(img1, (canvas.getWidth()/8),changey,null);

if(changey < canvas.getHeight())
{
changey +=5;
}else
{
changey =0;
}
invalidate();

}

}





No comments:

Post a Comment