Programming Android - Graphics
Programming Android - Graphics
ImageView Canvas
Draw to a View
Simple graphics, little or no updating
Draw to a Canvas
More complex graphics, with regular updates
Something that can be drawn, such as a bitmap, color, shape, etc. Examples: BitmapDrawable ShapeDrawable ColorDrawable
Can set Drawable objects on Views Can do this via XML or programmatically
Used for drawing primitive shapes Shape represented by a Shape class PathShape - lines RectShape - rectangles OvalShape - ovals & rings
Applications display two Shapes within a RelativeLayout The two shapes are partially overlapping and semi-transparent
A Bitmap (a matrix of Pixels) A Canvas for drawing to the underlying Bitmap A Drawing Primitive (e.g. Rect, Path, Text, Bitmap) A paint object (for setting drawing colors & styles)
Canvas supports multiple drawing methods drawText() drawPoints() drawColor() drawOval() drawBitmap()
Specifies style parameters for drawing, e.g., setStrokeWidth() setTextSize() setColor() setAntiAlias()
Application draws several boxes holding text, so using different paint settings each time
Use when updates are infrequent Create a custom View class System provides the canvas to the View when it calls the Views onDraw() method
Create a Custom SurfaceView Provide secondary thread for drawing Application provides its own canvas and has greater control over drawing
This application draws to custom View It has an Internal Thread that periodically wakes up and causes the View to move and to be redrawn
SurfaceView manages a low-level drawing area called a Surface The Surface represent a drawing area within the View hierarchy
Subclass SurfaceView & implement SurfaceHolder.Callback SurfaceHolder.Callback declares lifecycle methods that are called when the Surface changes
Draw
Canvas.drawBitmap()
Unlock Canvas
SurfaceHolder.unlockCanvasAndPost()
Changing the properties of a View over a period of time Size Position Transparency Orientation
This application uses the same shapes as the GraphicsShapeDraw applications Shows Cyan shape then fades to Magenta shape
Animates a series of Drawables Each Drawable is shown for a specific amount of time
A series of transformations applied to the content of a View Can Manipulate animation timing to give effect of sequential or simultaneous changes
ValueAnimator Timing engine TimeInterpolator defines how values change as a function of time AnimatorUpdateListener called back at every animation frame change TypeEvaluator Calculates a propertys value at a given point in time
Same as the GraphicsTweenAnimation, Uses the ViewPropertyAnimator class, which is a simplified animator for Views