Tuesday, August 31, 2010

Working With Canvas in Android

 Some Examples to work with Canvas


Drawing a Round Rectangle 


                Path path = new Path();
RectF rect=new RectF(60,  05, 300, 25);
// rectangle with 10 px Radius
path.addRoundRect(rect, 10, 10, Direction.CCW);
canvas.drawPath(path, p);

Drawing a text 

                              Paint p = new Paint();
             p.setColor(Color.WHITE);

                             p.setTextSize(16);
            Typeface tf=Typeface.SANS_SERIF ;
            p.setTypeface(tf);
            p.setFakeBoldText(true);


                            canvas.drawText("Map ", 380, 20,  p);

Drawing a Bitmap Image

        Bitmap mapbmp=BitmapFactory.decodeResource(getResources(), R.drawable.mapicon);
canvas.drawBitmap(mapbmp, 360, 05, p); 




Android Developers Blog

Ram's shared items