Users Online
· Guests Online: 154
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
023 Java Android Program to Animate a Bitmap
Java Android Program to Animate a Bitmap
This Android Java Program lets you create an Application to Animate a Bitmap.
Here is source code of the Program to create an Application to Animate a Bitmap. The program is successfully compiled and run on a Windows system using Eclipse Ide. The program output is also shown below.
Main Activity
package com.example.animatingbitmap;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
animate var;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
var = new animate(this);
setContentView(var);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Animate
package com.example.animatingbitmap;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;
public class animate extends View{
Bitmap bm;
int x, y;
public animate(Context context) {
super(context);
// TODO Auto-generated constructor stub
bm=BitmapFactory.decodeResource(getResources(), R.drawable.image4);
x = 0; y = 0;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Rect myrect = new Rect(0, 0, canvas.getWidth(),canvas.getHeight()/2);
Paint pa = new Paint();
pa.setColor(Color.BLUE);
pa.setStyle(Paint.Style.FILL);
canvas.drawRect(myrect, pa);
if (x < canvas.getWidth()) {
x += 10;
}
else {
x = 0;
}
if (y < canvas.getHeight()) {
y += 10;
}
else {
y = 0;
}
canvas.drawBitmap(bm, x, y, new Paint());
invalidate();//calls this method again and again
}
}
This Android Java Program lets you create an Application to Animate a Bitmap.
Here is source code of the Program to create an Application to Animate a Bitmap. The program is successfully compiled and run on a Windows system using Eclipse Ide. The program output is also shown below.
Main Activity
package com.example.animatingbitmap;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
animate var;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
var = new animate(this);
setContentView(var);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Animate
package com.example.animatingbitmap;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;
public class animate extends View{
Bitmap bm;
int x, y;
public animate(Context context) {
super(context);
// TODO Auto-generated constructor stub
bm=BitmapFactory.decodeResource(getResources(), R.drawable.image4);
x = 0; y = 0;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Rect myrect = new Rect(0, 0, canvas.getWidth(),canvas.getHeight()/2);
Paint pa = new Paint();
pa.setColor(Color.BLUE);
pa.setStyle(Paint.Style.FILL);
canvas.drawRect(myrect, pa);
if (x < canvas.getWidth()) {
x += 10;
}
else {
x = 0;
}
if (y < canvas.getHeight()) {
y += 10;
}
else {
y = 0;
}
canvas.drawBitmap(bm, x, y, new Paint());
invalidate();//calls this method again and again
}
}
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.