android - Can we have two canvases in an activity ? (OR) Having a canvas outside the onDraw() is not working -
@override protected void ondraw(canvas canvas) { // draw graphic objects ..... } public void displaycalc(){ //do calculation & display results near these graphic objects string result = string.valueof(value); //do calculation //display calculated values canvas c =new canvas(); paint paint = new paint(); paint.setstyle(paint.style.fill); paint.setantialias(true); paint.setcolor(color.white); c.drawtext(result,200,300,paint); } but if have same thing in function ondraw works fine. i know why or changes have make working
@override protected void ondraw(canvas canvas) { // draw graphic objects //do calculation & display results near these graphic objects ..... string result = string.valueof(value); //display calculated values paint paint = new paint(); paint.setstyle(paint.style.fill); paint.setantialias(true); paint.setcolor(color.white); canvas.drawtext(result,200,300,paint); }
if you're trying implement kind of double buffering, might want take @ this
i think problem need create bitmap, attach canvas it, like:
bitmap bitmap = bitmap.createbitmap(width, height, config.rgb_565); canvas c = new canvas(bitmap); // draw canvas.. // , when you're happy, draw bitmap onto canvas supplied ondraw. just creating canvas, doesn't make appear on screen.
you may want take at: this tutorial
if have surfaceview, can (don't have compiler, gist):
surfaceview view = (surfaceview)findviewbyid(r.id.view); surfaceholder holder = view.getholder(); // save can accessed function canvas c try { c = holder.lockcanvas(); // draw stuff } { if(null != c) { holder.unlockcanvasandpost(c); } }
Comments
Post a Comment