Loading

Wednesday, August 24, 2011

Example of drawing on View



package com.exercise.AndroidDraw;



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 AndroidDrawActivity extends Activity {



/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(new MyView(this));

}



public class MyView extends View {



public MyView(Context context) {

super(context);

// TODO Auto-generated constructor stub

}



@Override

protected void onDraw(Canvas canvas) {

// TODO Auto-generated method stub

super.onDraw(canvas);



int width = getWidth();

int height = getHeight();

int radius;



if (width > height){

radius = height/2;

}else{

radius = width/2;

}



Paint paint = new Paint();

paint.setStyle(Paint.Style.FILL);



paint.setColor(Color.RED);

canvas.drawPaint(paint);

paint.setColor(Color.BLUE);

canvas.drawCircle(width/2, height/2, radius, paint);

}



}

}

SHARE TWEET

Thank you for reading this article Example of drawing on View With URL http://x-tutorials.blogspot.com/2011/08/example-of-drawing-on-view.html. Also a time to read the other articles.

0 comments:

Write your comment for this article Example of drawing on View above!