0% found this document useful (0 votes)
42 views

Graphics

This document provides information on various graphics and animation techniques in Android, including: 1. It discusses different types of graphics drawing like using ImageViews, Canvas drawing, and Drawables. 2. It also covers animations using techniques such as PropertyAnimation, AnimationDrawable, and ValueAnimator. 3. The document provides code examples for tasks like drawing shapes, animating properties, and using SurfaceViews for graphics-intensive code.

Uploaded by

Dante Korinto
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Graphics

This document provides information on various graphics and animation techniques in Android, including: 1. It discusses different types of graphics drawing like using ImageViews, Canvas drawing, and Drawables. 2. It also covers animations using techniques such as PropertyAnimation, AnimationDrawable, and ValueAnimator. 3. The document provides code examples for tasks like drawing shapes, animating properties, and using SurfaceViews for graphics-intensive code.

Uploaded by

Dante Korinto
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 83

Romain

Chiappinelli

2D Graphics
ImageView
Canvas

View Animation
Property Animation

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

Applications display a single ImageView


ImageView holds an image of a bubble

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

Can draw to generic Views, or to


SurfaceViews

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

Used for more high-performance


drawing outside the UI thread

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

Set up SurfaceView
Draw to SurfaceView

Use SurfaceViews getHolder() to


acquire Surface

Register for callbacks with


SurfaceHolders addCallback()
surfaceCreate()
surfaceChanged()
surfaceDestroyed()

Create the thread on which drawing


operations will execute

Acquire lock on Canvas


SurfaceHolder.lockCanvas()

Draw
Canvas.drawBitmap()

Unlock Canvas
SurfaceHolder.unlockCanvasAndPost()

Changing the properties of a View over


a period of time
Size
Position
Transparency
Orientation

TransitionDrawable
AnimationDrawable
Animation

A 2-layer Drawable
Can fade between 1st & 2nd layers

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

Uses an Animation Drawable to present


a frame by frame animation

A series of transformations applied to


the content of a View
Can Manipulate animation timing to give
effect of sequential or simultaneous
changes

Application displays a single ImageView


and animates several of its properties

Animation - Changing properties of an


Object over a period of time

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

AnimatorSet combines individual


animations to create more complex
animations

Uses a ValueAnimator to animate


changing an ImageViews background
color

Same as the GraphicsTweenAnimation,


Uses the ViewPropertyAnimator class,
which is a simplified animator for Views

MultiTouch & Gestures

You might also like