Wednesday, July 7, 2010

Android 2D Graphics Example

This example shows how to use onDraw() method and create a simple drawing program. The only significant files are Draw activity and the DrawView.

MainActivity.java
public class MainActivity extends Activity { 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);      
        DrawView drawView = new DrawView(this);
        setContentView(drawView);
        drawView.requestFocus();
    }
}


public class DrawView extends View {
    Paint paint = new Paint();
    Context c;
    public DrawView(Context context) {
        super(context);
        c= context;    
        paint.setColor(Color.WHITE);
        paint.setAntiAlias(true);
    }

    @Override
   public void onDraw(Canvas canvas) {
            canvas.drawCircle(100, 100, 50, paint);
    }
}
}


1 comment:

  1. Nice information. Thanks for sharing. Appconsultio offers ongoing maintenance and support services to keep the apps up-to-date and functioning smoothly as new versions of the Android OS are released or as the app's requirements evolve. Our Mobile Application Developers in Pune have crafted an innovative app that is revolutionizing the way people interact with technology.

    ReplyDelete