Android plotting application method summary

Source: Internet
Author: User

In the Android operating system, there are many functional skills that can help us easily implement some requirements. For example, image processing. Here we will bring you some Android plotting methods, hoping that our friends can fully master these applications.

  • Summary of Android constructed block categories
  • Android Button rules
  • Analysis of Android simulated SD card Implementation Method
  • Android onKey Operation Method
  • Analysis of Android message passing application functions

Use drawRect and drawText in the Canvas class to draw various graphics and texts. For details about the Function list and parameter descriptions, see the sdk.

The image style is controlled by the paint parameter.

The Paint class also has many parameter setting methods.

Coordinates are managed by Rect and RectF

You can use Canvas, Paint, and Rect to draw most of the basic graphics needed in the game.

Precautions for Android plotting

To draw a solid rectangle, you need to set the paint attribute: paint. setStyle (Style. FILL); change the painting Style through several enumeration values of the Style.

The following is a bit messy. You can add some record points at any time and sort them out later ~~~~~

1. Rect object

A region object Rect (left, top, right, bottom) is a left closed and right open area, that is, using Rect. contains (left, top) is true, Rect. contains (right, bottom) is false

2. drawLine Method

DrawLine (float startX, float startY, float stopX, float stopY, Paint paint) is also a left closed right open range, will only be drawn to the stopX-1, stopY-1

Verification Method:

 
 
  1. Canvas c = canvas;  
  2. paint.setColor(Color.RED);  
  3. c.drawLine(x, y, x+c.getWidth()-1, y, paint);  
  4. c.drawLine(x, y+height-1, x+c.getWidth(), y+height-1, paint);  
  5. paint.setColor(Color.BLUE);  
  6. c.drawPoint(x+c.getWidth()-1, y, paint); 

It indicates that drawLine is not drawn to the last Vertex on the right.

3. drawRect (Rect r, Paint paint)

When a hollow rectangle is drawn, a left-closed and right-Closed Area is drawn.

Verification Method:

 
 
  1. rect.set(x, y, x+width, y+height);  
  2. paint.setStyle(Style.STROKE);  
  3. paint.setColor(Color.BLUE);  
  4. c.drawRect(rect, paint);  
  5. paint.setColor(Color.RED);  
  6. c.drawLine(x, y, x+width, y, paint);  
  7. c.drawLine(x, y+height, x+width, y+height, paint);  
  8. c.drawLine(x, y, x, y+height, paint);  
  9. c.drawLine(x+width, y, x+width, y+height, paint); 

When a solid rectangle is drawn, a left closed and right open area is drawn.

Verification Method:

 
 
  1. rect.set(x, y, x+width, y+height);  
  2. paint.setColor(Color.RED);  
  3. c.drawLine(x, y, x+width, y, paint);  
  4. c.drawLine(x, y+height, x+width, y+height, paint);  
  5. c.drawLine(x, y, x, y+height, paint);  
  6. c.drawLine(x+width, y, x+width, y+height, paint);  
  7. paint.setStyle(Style.FILL);  
  8. paint.setColor(Color.BLUE);  
  9. c.drawRect(rect, paint); 

This rule is also the same as that of j2s. In j2s, drawRect draws 1px more in length and width. SDK description:

The resulting rectangle will cover an area (width + 1) pixels wide by (height + 1) pixels tall. If either width or height is less than zero, nothing is drawn.

For example, when drawRect (10, 10,) is drawn, the result is a 2px high rectangle, with fillRect (10, 10, 1), the result is a 1px high rectangle

The above is a detailed introduction to Android plotting.

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.