[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.
- Protected void ondraw (canvas ){
- // Todo auto-generated method stub
- Super. ondraw (canvas );
- Paint. setantialias (true); // you can specify the paint brush to be non-sawtooth.
- Paint. setcolor (color. Black); // you can specify the paint color.
- Canvas. drawcolor (color. White); // white background
- Paint. setstrokewidth (float) 3.0); // line width
- Paint. setstyle (style. Stroke); // hollow Effect
- Rect R1 = new rect (); // rect object
- R1.left = 50; // left
- R1.top = 50; // above
- R1.right = 450; // right
- R1.bottom = 250; // bottom
- Canvas. drawrect (R1, paint); // draw a rectangle
- Rectf r2 = new rectf (); // rectf object
- R2.left = 50; // left
- R2.top = 400; // above
- R2.right = 450; // right
- R2.bottom = 600; // bottom
- Canvas. drawroundrect (R2, 10, 10, paint); // draw a rounded rectangle.
- }
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