Code example for Canvas

Methods: drawRGB, drawRect, drawText, restore, restoreToCount, save, saveLayer, translate

0
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRGB(128, 255, 128);
 
            canvas.save();
 
            canvas.translate(140.0f, 100.0f);
            drawStuff(canvas, Canvas.ALL_SAVE_FLAG);
 
            canvas.translate(0.0f, 200.0f);
            drawStuff(canvas, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
 
            canvas.restore();
        } 
 
        private void drawStuff(Canvas canvas, int saveFlags) {
            int count = canvas.saveLayer(0.0f, 0.0f, 200.0f, 100.0f, mLayerPaint, saveFlags);
 
            mRectPaint.setColor(0x7fff0000);
            canvas.drawRect(-20.0f, -20.0f, 220.0f, 120.0f, mRectPaint);
 
            mRectPaint.setColor(0xff000000);
            canvas.drawText("This is a very long string to overlap between layers and framebuffer",
                    -100.0f, 50.0f, mRectPaint);
 
            canvas.restoreToCount(count);
        } 
    } 
}