Monday, February 9, 2015

Android Canvas & Drawables Basics


The Android framework APIs provides a set of 2D-drawing APIs that allows application to render own custom graphics onto a canvas or to modify existing views to customise their look and feel. There are two ways to draw 2D graphics. 

1. Draw graphics or animations into a View object from layout. in this manner, drawing of graphics is handled by the Ssystems’s normal view hierarcy drawing process. - Application just define the graphics to go inside the view. 

2. Draw the application  graphics directly on to a Canvas. This way application personaly call the appropriate classes onDraw method by passing the canvas or one f the Canvas drwa() method In doing like this, application also in control of any animation.

Option 1 is suitable when we want to draw simple graphics that do not change dynamically and are not part of performance intensive game. 

Option 2 is suitable when application needs to re-draw itself regularly. Applications such as video games should draw on to canvas of its own. There are more than one way to do draw onto own canvas of application.

- In the same thread as UI Activity, where in application create a custom View component in the layout , call invalidate() and then handle the onDraw callback. 


- On a separate thread where in manage SurfaveView and perform draws to canvas as fast as the thread is capable (application need not to request invalidate) 

References: 
http://developer.android.com/guide/topics/graphics/2d-graphics.html

No comments:

Post a Comment