android-canvas&drawable
a Canvas
Canvas: Canvases
Used to render graphics on the screen, known as the canvas
Two introduction to canvas
Common classes
1 Clip: Clipping area
2 matrix: matrices
Divide the canvas into many squares
The rotation method is the canvas rotation
3 Save: Saves the state of the canvas
Restore: Restoring the state of the canvas
For example, rotate the canvas after painting the other content, save after recovery,
Common Draw methods:
Drawrectl: Draw a rectangle
Drawcircle: Draw a circle
DrawOval: Drawing an ellipse
DrawPath: Draw Path
DrawLine: Drawing Lines
Drawpoint: Draw points
DrawText: Drawing Text
Drawcolor: Setting Colors
Drawbitmap: Drawing Pictures
Sufaceview: often used in games
Graphical Dynamic Setting Method:
The number of frames that constantly refresh the drawing.
The main thread view:invalidate will invalidate the OnDraw method
Child thread View:postinvalidate will invalidate the OnDraw method
Three drawable Introduction
Common drawable:
Bitmapdrawable: Drawing, most commonly used
Shapedrawable: Painting the background
Picturedrawable: Drawing Pictures
Layoutdrawable: Drawing Layout
Custom drawable:
Ways to define and implement drawable:
1 Use the picture in the resource file:
Supported images have PNG (recommended), JPG (acceptable), GIF (not recommended)
GetResource () method to get resources within the Drawable folder
2 generating from an XML file
Define the XML file in the Drawable folder, define the layout in the activity, and get the XML resource
3 Encoding Custom constructs
Customizing a view class inherits from the Drawable class, overriding the method of the parent class
Four Nine-patch
1 Definition: 9-patch is a standard PNG image that includes a boundary of one pixel outside of two and the suffix must be. 0.png.
and stored in the Res/drawable directory of the project. If you extract the *.9.png from the apk file,
Note that it is removed from the empty packet pixel of the walk, and must be added when used
2 Area
Left and on-line: controlling stretch areas
Right line and downline: Content control Area
3 Use
Tools: Draw9patch.bat under the tool directory under the SDK
Press the left mouse button to select
Shift+ left mouse button, uncheck
When selected, there will be a black line indicating
A good 9-patch such as:
Android-canvas&drawable