Draw primitive shapes such as rectangle, circle etc in ANDROID, A simple example.

By | February 12, 2011

The following example shows how to draw a rectangle using the Paint Class in ANDROID. Just copy and paste the following code to your file and you are done.

package Draw2.pack;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

public class Draw2 extends Activity {

  public void onCreate(Bundle savedInstanceState) {
         setContentView(new myView(this));

  private class myView extends View{

      public myView(Context context) {

      protected void onDraw(Canvas canvas) {

          Paint myPaint = new Paint();
          canvas.drawRect(10, 10, 100, 100, myPaint);

Leave a Reply

Your email address will not be published. Required fields are marked *