首頁 > web前端 > H5教程 > 主體

Canvas and Drawables 翻譯第一集

黄舟
發布: 2017-01-16 16:38:14
原創
1472 人瀏覽過

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

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

Canvas and Drawables 畫板和圖紙(圖紙是可拉伸的圖紙)

IN THIS DOCUMENT

Draw with a Canvas

On a View Drawables

Creating from resource
images
Creating from resource
XML

Shape Drawable
Nine-patch

SEE ALSO
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,

Android'll typically do so in one of of two API:

Android'll typically do so in one of of two API: 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 hiermarchy soo 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
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 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,當你想繪製一個簡單的圖形(圖形或不是效能加強的遊戲的一部分,這個時候,吧圖形繪製到一個視圖(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 should be drawing to the Canvas on its own. However, thereones more thanever dole do. :

選項b,當你的應用需要按時地重繪自己的時候,繪製到一個畫板(Canvas)裡是一個更好的選擇。例如視頻遊戲應用應該繪製到畫板上。不管怎麼說,有很多方法可以做這件事。


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

draw...()
登入後複製

and
then handle theActivityr.用你的layout建立一個自訂視圖元件(View component),呼叫invalidate()方法,然後處理onDraw()回呼。
Or, in a separate thread, wherein you manage a
invalidate()
登入後複製

and
perform draws to the Canvas as fast as your thread is capable (you do not need to request
reee
,在其中你管理一個SurfaceView和盡可能快的將圖形繪製到畫板(Canvas)上(你不需要請求Invalidate()

)。

以上就是Canvas and Drawables 翻譯第一集的內容,更多相關內容請關注PHP中文網(www.php.cn)!


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板