Introduction to Android--ui related common classes

Source: Internet
Author: User

first, the Canvas class Android.graphics.Canvas

Canvas is like a paper in a mobile phone, and we can draw graphics or images on canvas. In general, when we use Android to paint, we need four components:
1. Bitmap: Contains pixels
2. Canvas artboard: Include painting content, write bitmap
3, the initial graphics: such as Rect, Bitmap, text, etc.
4, Paint: Used to describe the above initial graphic color and type, etc.
The canvas class provides three construction methods:
Public canvas (); Constructs a default, non-parametric canvas object
Public canvas (Bitmap Bitmap); Constructs a canvas object based on a Bitmap
Public Canvas (GL GL); Constructs an object according to a GL
Let's look at the methods provided by the canvas class:
In the methods provided by the canvas class, more commonly used is the method that starts with draw, which is easy to understand is to draw a graphic into the artboard, such as to draw a bitmap into the canvas, fill the shape with color, and so on.


Second, Paint class Android.graphics.Paint

The Paint class contains information such as geometry, text, bitmap types, and colors, and if you think of the canvas class as an artboard, we can think of the paint class as a brush, and you can draw different colors and styles of graphics, text, and so on as needed.
The Paint class has three methods of construction:
Public paint () constructs a default paint object
Public
Paint (int flags), which constructs a paint object according to the specified flags, which can be used after creation
SetFlags () method to change
Public paint paint to construct a paint object based on the specified Paint object
The Paint class provides many ways to set and get the properties of a paint object, such as:
public int GetColor () gets the color value of the Paint object
Public Colorfilter getcolorfilter () Get color filter
public float gettextsize () Gets the font size value
public void SetStyle (Paint.style Style) sets the type of Paint

Three Color class Android.graphics.Color

This class defines methods to create and transform color values. Colors are represented as encapsulated values, which consist of four bytes: alpha, red, green, blue, which are not from the left, meaning that any transparency is stored only in the Alpha section, not in the color component. Each section is saved in the following order: (ALPHA&LT;&LT;24) | (red<<16) |<green<<8) |blue. The range of values for each part is between 0-255 and 0 means that this part does not work, and 255 means that 100% works. Therefore the opaque black should be 0xff000000, the opaque white should be 0xFFFFFFFF.
The color class provides 12 constant values to represent different color values, and we can call these constant values directly in the development project to set the objects we want to decorate with text, graphics, and so on.
The color class provides an argument-free construction method color ()
The color class provides some methods for creating and converting colors values as follows:
Three of these methods are used to return a color constant value of the red-green-blue separations, the values are 0-255, respectively, as follows:
public static red (int color);
public static green (int color);
public static blue (int color);
where public static int rgb (int red,int green,int blue), input red-green-blue three-color, return an RGB color value.
Here are a few ways you can refer to the Android API to understand:
public static int Hsvtocolor (int alpha,float[] HSV);
public static int Hsvtocolor (float[] HSV);
public static void rgbtohsv (int red,int green,int blue,float[] HSV);
public static int alpha (int color);
public static int ARGB (int alpha,int red,int green,int blue);
public static COLORTOHSV (int color,float[] HSV);
public static Parsecolor (String colorstring);



Four. Typeface class Android.graphics.Typeface

The typeface class defines the intrinsic types of fonts and fonts. This class is used in brush paint settings, such as using the TEXTSIZE,TEXTSKEWX and Textscale settings to specify how text is displayed and measured when it is painted.

Typeface provides a number of constant values to represent some of its own properties, such as Bold,bold_italic,italic, which developers can use Defaultfrophone sdntyle (int style) to gain an intrinsic Typeface object. Readers can refer to the detailed API documentation and no longer repeat it here.

Let's take a look at the main methods of typeface.

The typeface class does not have a constructor, usually if a class does not have a constructor to generate an object entity by construction, there is typically a specific static method to obtain the entity of the class. Typeface provides four static methods for indirectly obtaining typeface entities, respectively, as follows:

public static Typeface Create (Typeface family,int style);

This method returns a typeface that matches the existing typeface glyph system and that the type is the specified type. This method can be called if you want a typeface that is similar to the existing typeface glyph system but has a different style. Where the family parameter can be null, and if it is empty, it is selected from the default typeface glyph system.

public static Typefaxe Create (String familyname,int style);

This method returns a typeface object by the name of the given glyph system, Familyname, and the specified type. If the name of the given glyph system is null, we can get the true properties of the returned typeface object through the GetStyle () method.

public static Typeface Createfromasset (Assetmanager mgr,string path);

This method returns a typeface object through the specified font data. The first parameter is the resource manager, and the second parameter is the specified font type.

public static Typeface Defaultfrophone sdntyle (int style); This method returns a Typeface object of the specified type

The typeface also provides three additional methods:

public int GetStyle (); This method returns the intrinsic Type property of typeface

Public final Boolean IsBold (); if GetStyle () has a bold bit group will return true

Public final Boolean Isitalic () if GetStyle () has italic bit group will return true

V. Path class Android.graphics.Path

The path class (a set of regions) depicting a variety of geometries such as line segments, two curves, three curves, etc.

Call the Canvas.drawpath () method to draw the path to the artboard as defined by the paint, or to fill out the drawing, or to draw the graphic in the manner specified by paint.

Vi. RECTF class Android.graphics.RectF and Rect class Android.graphics.Rect

RECTF This class contains four single-precision floating-point coordinates for a rectangle. The rectangle represents a rectangle by the coordinates of the upper and lower left and right 4 sides. These coordinate value properties can be accessed directly, and the width () and height () methods can be used to obtain the width and height of the rectangle. Note: Most methods do not check these coordinate classifications for errors (that is, left<=right and top& lt;=bottom).

RECTF there are altogether four methods of construction:

RECTF () constructs an argument-free rectangle

RECTF (float left,float top,float right,float bottom) constructs a rectangle with 4 parameters specified

RECTF (Rect F R) constructs a RECTF object based on the specified RECTF object (the left coordinate of the object is unchanged)

RECTF (rect R) constructs a RECTF object based on the given Rect object

RECTF offers a number of methods, the following are some methods:

Public boolean contain (RECTF R); Determines whether a rectangle is within this rectangle, and returns True if within the rectangle or equivalent to the rectangle, as well as a public boolean contain (float left, float top,float right,float bottom) and public Boolean contain (float x,float y).

public void Union (float x,float y) updates this rectangle so that it contains the rectangle itself and (x, y) this point.

The RECTF class provides a simple, easy-to-understand approach, which is no longer one by one.

The Android.graphics.Rect class, which is similar to Android.graphics.RectF, differs in that the coordinates of a RECT class are represented by shaping, while the coordinates of RECTF are represented by a single-precision floating-point type. Everyone here must pay attention to AH.

Seven, point class Android.graphics.Point

This class literally means that it is related to dots and is a point object class.

This class has two properties, namely: x-coordinate and y-coordinate.

There are three constructors: Point (), point (int x,int y), point (Point P)

The main methods are:

public void set (x, y); re-set X, y coordinates

Public final void offset (int dx,int dy); Give coordinates a compensation value that can make positive or negative.

Public final void negate (); negative coordinate value.

The point class is similar to Android.graphics.PointF, where the difference is that the type of the coordinate value is the int type, and the coordinate value of the latter is the float type. In addition, the PointF class adds several methods, such as:

Public final float length (); return (0,0) the distance to the point.

public static float Length (float x,float y); returns the distance (0,0) point to (x, y) point.

Introduction to Android--ui related common classes

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.