Android-canvas&drawable

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.