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 some ca
Solution 1:
If you're trying to implement some kind of double buffering, you might want to take a look at this
I think your problem is that you need to create a bitmap, then attach the canvas to it, something like:
Bitmapbitmap= Bitmap.createBitmap(width, height, Config.RGB_565);
Canvasc=newCanvas(bitmap);
// then draw to the canvas..// and when you're happy, draw the bitmap onto the canvas supplied to onDraw.
Just creating a canvas, doesn't make it appear on the screen.
You may also want to take a look at: this tutorial
If you have a surfaceView, then you can do something like this (don't have a compiler, but hopefully you get the gist):
SurfaceViewview= (SurfaceView)findViewById(R.id.view);
SurfaceHolderholder= view.getHolder(); // save this where it can be accessed by your function
Canvas c
try {
c = holder.lockCanvas();
// draw stuff
}
finally {
if(null != c) {
holder.unlockCanvasAndPost(c);
}
}
Solution 2:
If you want to have two SurfaceViews, than simply add them to your layout and give them both an own thread (or combine both drawings in one thread).
I don't get it why you want to draw on a separate canvas in your first method sample... Maybe you provide more information for what you try to achieve.
Post a Comment for "Can We Have Two Canvases In An Activity ? (or) Having A Canvas Outside The Ondraw() Is Not Working"