2D drawing with Android -
im trying understand how android drawings work.
i hoping can explain how drawing components relate each other (view, drawable, canvas, bitmap)
it seems confusing , documentation doesnt job explaining it.
does bitmap inside canvas object injected in view's via ondraw() represent whole display, or chunk view draws?
what drawable do, objects encapsulate set of commands canvas object?
im hoping can me basic understanding on how works, dont have eny java background action script , c# (silverlight).
this pretty vague question, i'll give shot. first answer on site , no means expert have found myself doing lot of tinkering drawing in android.
from i've read , experienced, each view has bitmap, used draw view on screen. each view has canvas. canvas allows programmer control drawn onto bitmap.
every view object has ondraw(canvas c)
method used draw it. if want draw yourself, can create subclass of view
class extending view , can override ondraw(canvas c)
method draw whatever want. draw onto view using canvas
object provided parameter ondraw()
method.
a drawable object can drawn. still image (bmp, png, jpg,etc), icon, animated gif, etc. drawable created existing image want draw onto screen. done in 2 steps: including image project, drawing image.
to include image project can drag 1 of res/drawable folders in project directory in eclipse.
once image file included project, r.java file automatically updated unique id image file. load image file drawable in code, drawable d = getresources().getdrawable(r.id.imagefile);
. draw on canvas, set size , location using d.setbounds()
method , use d.draw(canvas)
in ondraw()
method draw in view.
the canvas object provided ondraw() method has many useful functions drawing onto view. play around it, that's best way can learn how use it. also, don't forget check out android developer site see full listing of methods.
what hoping drawing? if trying make game, should using surfaceview
class.
here's example of custom view class:
public class customview extends view{ public void ondraw(canvas c){ c.drawcolor(color.red); } }
this view, when created, should draw filled color red.
Comments
Post a Comment