Android--Custom View Mini demo, about rect drawing Android Robot (one)

Source: Internet
Author: User

1, about the difference between the rect and the RECTF class has not been to pay attention to it, just learned that it is used to determine the area of the rectangle, but rect is the coordinates of the int type and RECTF is the float type of coordinates, so RECTF to be more accurate. Now it is time to use paint to draw a picture of a robot, such as a picture of a robot:

2, look at the effect we made.

And then look at the code, which is basically using the RECTF class to manipulate

Package Com.wangjitao.myview.view;import Android.content.context;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.graphics.rectf;import Android.util.attributeset;import android.view.view;/** * Created by Wangjitao on 2016/10/10 0010.    * Primarily for rectangles using */public class Myrectfview extends View {public Myrectfview (context context) {super (context);    } public Myrectfview (context context, AttributeSet Attrs) {Super (context, attrs); } public Myrectfview (context context, AttributeSet attrs, int defstyleattr) {Super (context, Attrs, defstyleattr    );        } @Override protected void OnDraw (canvas canvas) {canvas.drawcolor (color.white);        Paint paint = new paint ();        Paint.setantialias (TRUE);        Paint.setcolor (0xffa4c739);        Draw the robot's head (a semicircle arc) RECTF rectf_head = new RECTF (10, 10, 100, 100);        Set the offset rectf_head.offset (100, 20); Draw the curve, and remove the center of the center canvas. DrawArc (Rectf_head, -10, -160, false, paint);        Draw eyes (eyes are two white small circles) paint.setcolor (color.white);        Canvas.drawcircle (135, 4, paint);        Canvas.drawcircle (175, 4, paint);        Draw two antennas (two straight lines) Paint.setcolor (0xffa4c739);        Paint.setstrokewidth (2);        Canvas.drawline (+, 135, n, paint);        Canvas.drawline (the 175, the other, the paint);    Draw the body (a simple rounded rectangle, using two rectangles, the first rectangle is the normal rectangle, the second rectangle is the rectangle to be rounded) canvas.drawrect (A, x, Max, Max, paint);        Draw Rectangle RECTF rectf_body = new RECTF (110, 140, 200, 160);    Canvas.drawroundrect (Rectf_body, ten, ten, paint);        Draw rounded rectangles//draw arms (rectangles with arcs) RECTF rectf_arm = new RECTF (85, 75, 105, 140);    Canvas.drawroundrect (Rectf_arm, ten, ten, paint);                            Draw left arm Rectf_arm.offset (120, 0);    Set the offset on the x-axis by 120 pixels canvas.drawroundrect (Rectf_arm, ten, ten, paint); Draw right arm//Draw two legs (also two rectangular rectangles) rectf Rectf_leg = new RECTF (125, 150, 145, 200);    Canvas.drawroundrect (Rectf_leg, ten, ten, paint);                            Draw the left leg Rectf_leg.offset (40, 0);    Set the offset on the x-axis by 40 pixels canvas.drawroundrect (Rectf_leg, ten, ten, paint); Draw the right Leg}}

  

Android--Custom View Mini demo, about rect drawing Android Robot (one)

Related Article

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.