The color gradient direction of the SweepGradient is not a ring, but a fan-shaped sweep is taken as the center of a certain point.
The constructors of SweepGradient:
Public SweepGradient (float cx, float cy, int [] colors, float [] positions)
Public SweepGradient (float cx, float cy, int color0, int color1)
Cx, cy specify the center, color1, color0, or colors specify the gradient color. When more than two colors are used, you can also use positions to specify the relative position of each color, if positions is set to NULL, the color is evenly distributed.
The base classes of LineerGradient, RadialGradient, and SweepGradient classes are Shader (similar to the Brush class in GDI). Shader defines a Local Matrix corresponding to it and can perform Coordinate Transformation on Shader. In this example, the Shader's LocalMatrix is used to rotate different angles to form the animation effect:
[Java]
Float x = 160;
Float y = 100;
MShader = new SweepGradient (x, y, new int [] {Color. GREEN,
Color. RED,
Color. BLUE,
Color. GREEN}, null );
MPaint. setShader (mShader );
...
Protected void onDraw (Canvas canvas ){
...
MMatrix. setRotate (mRotate, x, y );
MShader. setLocalMatrix (mMatrix );
MRotate + = 3;
If (mRotate> = 360 ){
MRotate = 0;
}
Invalidate ();
...
}
Float x = 160;
Float y = 100;
MShader = new SweepGradient (x, y, new int [] {Color. GREEN,
Color. RED,
Color. BLUE,
Color. GREEN}, null );
MPaint. setShader (mShader );
...
Protected void onDraw (Canvas canvas ){
...
MMatrix. setRotate (mRotate, x, y );
MShader. setLocalMatrix (mMatrix );
MRotate + = 3;
If (mRotate> = 360 ){
MRotate = 0;
}
Invalidate ();
...
} In this example, you can press the "D", "T" key to display the usage of the Paint Dither (Dither definition can be found in the Android ApiDemos example resolution (59): Graphics-> ColorFilters) and the display effects of different "scanning speeds:
Author: mapdigit