Drawroundrect method: Draw a rounded rectangle

Source: Internet
Author: User
[Function description] This method is used to draw a rounded rectangle on the canvas by specifying the rectf object and the radius of the rounded corner. This method is the main method to draw a rounded rectangle. You can also set the hollow effect of the paint brush to draw a hollow rounded rectangle.

[Basic syntax] public void drawroundrect (rectf rect, float RX, float ry, paint)

Parameter description

Rect: rectf object.

RX: the radius of the rounded corner in the X direction.

Ry: the radius of the rounded corner in the Y direction.

Paint: the paint brush used for painting.

[Demo] the following code demonstrates how to draw a rounded rectangle on the canvas.

  1. Protected void ondraw (canvas ){
  2. // Todo auto-generated method stub
  3. Super. ondraw (canvas );
  4. Paint. setantialias (true); // you can specify the paint brush to be non-sawtooth.
  5. Paint. setcolor (color. Black); // you can specify the paint color.
  6. Canvas. drawcolor (color. White); // white background
  7. Paint. setstrokewidth (float) 3.0); // line width
  8. Paint. setstyle (style. Stroke); // hollow Effect
  9. Rect R1 = new rect (); // rect object
  10. R1.left = 50; // left
  11. R1.top = 50; // above
  12. R1.right = 450; // right
  13. R1.bottom = 250; // bottom
  14. Canvas. drawrect (R1, paint); // draw a rectangle
  15. Rectf r2 = new rectf (); // rectf object
  16. R2.left = 50; // left
  17. R2.top = 400; // above
  18. R2.right = 450; // right
  19. R2.bottom = 600; // bottom
  20. Canvas. drawroundrect (R2, 10, 10, paint); // draw a rounded rectangle.
  21. }

In this Code, first set the color of the paint brush and set the canvas to a white background. Then, set the width of the paint brush and the hollow effect to draw the hollow moment. Finally, call the drawrect method to draw a rectangle on the canvas, and call the drawroundrect method to draw a rounded rectangle on the canvas. When you run this code, you can see the display effect shown in 8.18 on the mobile phone screen.

 
Figure 8.17 draw a rectangle
 
Figure 8.18 draw a rounded rectangle
[Responsible editor: Book Tel :( 010) 68476606]

Drawroundrect method: Draw a rounded rectangle

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.