Android Adventures - Beginning Bitmap Graphics
Written by Mike James   
Monday, 27 July 2015
Article Index
Android Adventures - Beginning Bitmap Graphics
A First Graphic
Simple Animation
Timer and threads
Listing and Summary


The complete listing of the animation program is:

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends ActionBarActivity {

 private int width=800, height=800;

 private float x=463,y=743,vx=1,vy=1,r=30;
 private Canvas c;
 private Paint paint;
 private ImageView imageview;

 protected void onCreate(Bundle savedInstanceState) {

  Bitmap b = Bitmap.createBitmap(width,    
  c = new Canvas(b);

  paint = new Paint();

  imageview=(ImageView) findViewById(;
Timer timer=new Timer();
   new TimerTask(){

    public void run() {

      new Runnable() {
       public void run() {
   },0,10 );

 void update(){
  c.drawCircle(x, y, r, paint);
  c.drawCircle(x, y, r, paint);



Where Next

There is so much to learn about graphics it is difficult to pick out things you need to know. If you want to find out more about how the standard UI works you need to look into the OnDraw event and how to create your own View object that render graphics. You need to find out about Android's vector graphics using shapes and path. You need to know about the different types of animation that are available and eventually you need to learn about OpenGL and its support for hardware accelerated 2D and 3D graphics. 


  • The subject of Android graphics is huge and there is always more than one way to approach any task. This chapter is a first look at what you might call UI-based graphics.

  • The Bitmap is the basic graphics object. It consists of a rectangle of pixels that can be set to any color.

  • The ImageView is a general purpose UI component that can be used to display a range of graphics objects including a Bitmap.

  • You can draw on a Bitmap using a Canvas object which has a large number of different drawing methods.

  • The color and drawing style used by many of the Canvas methods is determined by the properties of a Paint object.
  • The Canvas object also supports transformations which can be use to modify where a graphic is drawn, its size, rotation etc.

  • Transformations can be used to standardize the drawing of graphics objects at the origin.

  • Transformations can also be used to change the default pixel coordinate system to anything you want to use.

  • Simple animation is possible using nothing but a Bitmap, Canvas and an ImageView

  • Only the UI thread can modify the UI.

  • The Android Timer can be used to animate 2D graphics but you have ensure that its runs the code on the UI thread using the RunOnUIThread method. 

You can download the code for the animation program from the CodeBin. (Note you have to register first).


androidJavaSmallAndroid Programming In Java:
Starting With an App
Third Edition

Is now available in paperback and ebook.

Available from Amazon.



  1. Getting Started With Android Studio 3
  2. The Activity And The UI
  3. Building The UI and a Calculator App
  4. Android Events
         Extract: Using Lambdas 
  5. Basic Controls
  6. Layout Containers
  7. The ConstraintLayout
        Extract: Guidelines and Barriers
  8. UI Graphics A Deep Dive
        Extract: Programming the UI ***NEW
  9. Menus & The Action Bar
  10. Menus, Context & Popup
  11. Resources
  12. Beginning Bitmap Graphics
        Extract: Simple Animation
  13. Staying Alive! Lifecycle & State
  14. Spinners
  15. Pickers
  16. ListView And Adapters

If you are interested in creating custom template also see:

Custom Projects In Android Studio




To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter,FacebookGoogle+ or Linkedin,  or sign up for our weekly newsletter.






or email your comment to:


Last Updated ( Wednesday, 12 October 2016 )