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:
- Canvas c = canvas;
- paint.setColor(Color.RED);
- c.drawLine(x, y, x+c.getWidth()-1, y, paint);
- c.drawLine(x, y+height-1, x+c.getWidth(), y+height-1, paint);
- paint.setColor(Color.BLUE);
- 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:
- rect.set(x, y, x+width, y+height);
- paint.setStyle(Style.STROKE);
- paint.setColor(Color.BLUE);
- c.drawRect(rect, paint);
- paint.setColor(Color.RED);
- c.drawLine(x, y, x+width, y, paint);
- c.drawLine(x, y+height, x+width, y+height, paint);
- c.drawLine(x, y, x, y+height, paint);
- 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:
- rect.set(x, y, x+width, y+height);
- paint.setColor(Color.RED);
- c.drawLine(x, y, x+width, y, paint);
- c.drawLine(x, y+height, x+width, y+height, paint);
- c.drawLine(x, y, x, y+height, paint);
- c.drawLine(x+width, y, x+width, y+height, paint);
- paint.setStyle(Style.FILL);
- paint.setColor(Color.BLUE);
- 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.