首页 > web前端 > H5教程 > Canvas and Drawables 翻译第一集

Canvas and Drawables 翻译第一集

黄舟
发布: 2017-01-16 16:38:14
原创
1490 人浏览过

Android官方原文地址:http://developer.android.com/guide/topics/graphics/2d-graphics.html

------以下的翻译融入了自己的思考,便于理解,很多地方翻译并不是很恰当,所以配上了英文原文

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中文网(m.sbmmt.com)!


相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板