------以下的翻译融入了自己的思考,便于理解,很多地方翻译并不是很恰当,所以配上了英文原文
Canvas and Drawables 画板和图纸(图纸是可拉伸的图纸)
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框架APIs提供了一系列的2D绘制APIs,这些APIs允许你渲染你自己的自定义图形(Graphics)到画板(Canvas)上,或者修改已经存在的视图(Views)来定制它们的效果和体验。当绘制2D图形的时候,一般有两种方式:
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.
绘制你的图形(Graphics)或动画到一个视图(View)对象里面,通过布局文件(layout)。用这种方式,你的图形的绘制 将要被系统的正规的 视图层级绘制进程处理---你只要简单的定义图形到你的视图(View)里面。这种方式估计是说xml中定义的背景图片或ImageView里的src属性。
Draw your graphics directly to a Canvas. This way, you personally call the appropriate class's
onDraw()
method
(passing it your Canvas), or one of the Canvas
draw...()
).In doing so, you are also in control of any animation.
直接绘制你的图形(Graphics)到一个画板(Canvas),这种方法,你要亲自调用适当类的onDraw()方法(传入你的Canvas),或者Canvas draw...()方法之一(比如drawPicture())。这样做,你也能够把控任何动画。
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.
选项a,当你想绘制一个简单的图形(Graphics),这个图形不需要动态改变或不是性能加强的游戏的一部分,这个时候,吧图形绘制到一个视图(View)里,是你最好的选择。例如:当你想显示一张静态的图形或预先定义好的动画,你应当将你的图形绘制到一个视图(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:
选项b,当你的应用需要按时地重绘自己的时候,绘制到一个画板(Canvas)里是一个更好的选择。例如视频游戏应用应该绘制到画板上。不管怎么说,有很多方法可以做这件事。
In the same thread as your UI Activity, wherein you create a custom View component in your layout, call
invalidate()
and
then handle the
onDraw()
callback.
在和你UI Activity 的同一个线程里,在其中用你的layout创建一个自定义视图组件(View component),调用invalidate()方法,然后处理onDraw()回调。
Or, in a separate thread, wherein you manage a
SurfaceView
and
perform draws to the Canvas as fast as your thread is capable (you do not need to request
invalidate()
).或者,在一个独立分开的线程里,在其中你管理一个SurfaceView和尽可能快的将图形绘制到画板(Canvas)上(你不需要请求Invalidate()
)。
以上就是Canvas and Drawables 翻译第一集的内容,更多相关内容请关注PHP中文网(www.erdangjiade.com)!
友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群