Android Graphics Example

This example demonstrates basic drawing concepts using the Google AndroidSDK. The best way to understand a drawing api is to actually use it. This example extends Activity, creates a subclass of View and overrides the View.onDraw(). All of the drawing code in this example is located in the onDraw() method.

Android drawing example

Let’s take a quick tour of the DrawDemo screenshot. The blue circle in the upper left corner was drawn without anti-aliasing, notice the jagged circumference. The blue circle on the right was drawn with anti-aliasing turned on, thus the smooth circumference. “Style.STROKE” was drawn with Paint.Style.STROKE and paint.setAntiAlias(false). “Style.FILL” was drawn with Paint.Style.FILL and paint.setAntiAlias(true). A box was drawn around “!Rotated” by getting a bounding Rect that surrounds that same text. The “Rotated!” text was drawn by first rotating the canvas by 45 degrees, pivoting on the bounding Rect center point and then drawing the text. The triangles demonstrate using the Shape class and using a single instance to draw the shape at different locations with the Shape offset method. The “After canvas.restore()” text demonstrates how to undo the canvas.rotate(); Finally, there’s a an example of how to draw a dashed line using a DashPathEffect.