Drawing and Working With Animation
Drawing and Working With Animation
Method Description
drawLine(x1, y1, x2, y2, paint) Draws a line
drawRect(left, top, right, bottom,
Draws a rectangle
paint)
drawCircle(cx, cy, radius, paint) Draws a circle
drawText(text, x, y, paint) Draws text
Draws a bitmap
drawBitmap(bitmap, x, y, paint)
(image)
Common Paint Properties
Property Description
Sets the color of
setColor(Color.RED)
drawing
setStyle(Paint.Style.FILL) Fills the shape
setStyle(Paint.Style.STROKE
Draws only the border
)
Sets the thickness of
setStrokeWidth(5)
lines
// Draw a line
canvas.drawLine(50, 50, 300, 50, paint);
// Draw a circle
canvas.drawCircle(200, 200, 100,
paint);
// Draw text
paint.setStyle(Paint.Style.FILL);
canvas.drawText("Hello, Canvas!", 50,
600, paint);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap,
200, 200, true);
canvas.drawBitmap(scaledBitmap, 100, 100, null);
android:toDegrees="360
"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
Property Animations were introduced in
Android API 11