Home > Web Front-end > H5 Tutorial > body text

Canvas and Drawables Translation Episode 1

黄舟
Release: 2017-01-16 16:38:14
Original
1433 people have browsed it

Android official original text address: http://developer.android.com/guide/topics/graphics/2d-graphics.html

------The following translation incorporates my own thinking, To facilitate understanding, the translation in many places is not very appropriate, so the original English text

Canvas and Drawables drawing board and drawings (the drawings are stretchable drawings)

IN THIS DOCUMENT

Draw with a Canvas

On a View
On a SurfaceView

Drawables

Creating from resource
images
Creating from resource
XML

Shape Drawable
Nine-patch

SEE ALSO

OpenGL with the Framework APIs
RenderScript

The Android framework APIs provides a set of 2D-drawing APIs that allow you to render your own custom graphics onto a canvas or to modify existing Views to customize their look and feel. When drawing 2D graphics,
you'll typically do so in one of two ways :
Android framework APIs provide a series of 2D drawing APIs. These APIs allow you to render your own custom graphics (Graphics) to the artboard (Canvas), or modify existing views (Views) to customize them. Effect and experience. When drawing 2D graphics, there are generally two ways:

Draw your graphics or animations into a View object from your layout. In this manner, the drawing of your graphics is handled by the system's normal View hierarchy drawing process — you simply define the graphics to go inside
the View.
Draw your graphics (Graphics) or animation into a View (View) object, through the layout file (layout). This way, the drawing of your graphics will be handled by the system's regular view-level drawing process -- you simply define the graphics into your view. This method probably refers to the background image defined in xml or the src attribute in ImageView.
Draw your graphics directly to a Canvas. This way, you personally call the appropriate class's

onDraw()
Copy after login

method
(passing it your Canvas), or one of the Canvas

draw...()
Copy after login

).In doing so, you are also in control of any animation.
Draw your graphics (Graphics) directly to a drawing board (Canvas). In this method, you have to personally call the onDraw() method of the appropriate class (pass into your Canvas), or one of the Canvas draw...() methods (such as drawPicture()). By doing this, you can also control any animation.

Option "a," drawing to a View, is your best choice when you want to draw simple graphics that do not need to change dynamically and are not part of a performance-intensive game. For example, you should draw your
graphics into a View when you want to display a static graphic or predefined animation, within an otherwise static application. Read Drawables for
more information.
Option a, when you want to draw a simple graphic (Graphics), this graphics does not need to change dynamically or is not part of the performance-enhanced game. At this time, drawing the graphics into a view (View) is your best choice. For example: when you want to display a static graphic or a predefined animation, you should draw your graphic into a View.
Option "b," drawing to a Canvas, is better when your application needs to regularly re-draw itself. Applications such as video games should be drawing to the Canvas on its own. However, there's more than one way
to do this:
Option b, when your application needs to redraw itself on time, drawing into a canvas is a better choice. For example a video game application should be drawn to the artboard. Anyway, there are many ways to do it.

In the same thread as your UI Activity, wherein you create a custom View component in your layout, call

invalidate()
Copy after login
Copy after login

and
then handle the

onDraw()
Copy after login

callback.
In the same thread as your UI Activity, create a custom view component (View component) with your layout, call the invalidate() method, and then handle the onDraw() callback.
Or, in a separate thread, wherein you manage a

SurfaceView
Copy after login

and
perform draws to the Canvas as fast as your thread is capable (you do not need to request

invalidate()
Copy after login
Copy after login

). Or, in a separate thread, where you manage a SurfaceView and draw graphics to the Canvas as quickly as possible (you don't need to request Invalidate()

).

The above is the content of the first episode of Canvas and Drawables translation. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!