Android Canvas Explore

Source: Internet
Author: User

protected void OnDraw (canvas canvas) {//TODO auto-generated method Stubsuper.ondraw (canvas);//construction of two brushes, one red, one green paint Paint_green = Generatepaint (Color.green, Style.stroke, 3); Paint paint_red   = Generatepaint (color.red, Style.stroke, 3);//Constructs a rectangle rect rect1 = new Rect (0,0,400,220);// Draw the Border Canvas.drawrect (Rect1, Paint_green) with green before panning the canvas, and then redraw the rectangle canvas.translate (100, 100) with a red border after panning the canvas. Canvas.drawrect (Rect1, paint_red);} Private Paint generatepaint (int color,paint.style style,int width) {Paint paint = new Paint ();p aint.setcolor (color); Paint.setstyle (Style);p aint.setstrokewidth (width); return paint;}

Code Analysis:

In this code, for the same rectangle, use green to draw a rectangular border before panning the canvas, and then use red to draw a rectangular border. Do you think the two frames will overlap? The actual result is this.



A Canvas object is called before and after, however, this object is not directly assigned to the graph, this object is actually a "layer" for drawing, but it is not, each call to draw and other functions, the completion of a layer, so although the call is a canvas the same object, Actually calling a different layer

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Canvas Explore

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.