Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Directory (?) [+]
Android color Processing (vi) Radialgradient ring rendering
public radialgradient(float x, float y, float radius, int[] colors, float[] positions,shader.tilemode tile) Float x: center x coordinate float y: center y coordinate float radius: radius
Int[] Colors: Render color Array
Floate[] Positions: Relative position array, nullable, NULL, nullable, color evenly spaced along gradient line
Shader.tilemode tile: renderer tiling mode
public radialgradient(float x, float y, float radius, int color0, int color1,shader.tilemode tile) /c0>Float x: center x coordinate float y: center y coordinate float radius: radius
int COLOR0: Center color
int color1: Round edge Color
Shader.tilemode tile: renderer tiling mode
;
Code:
Mainactivity:
[Java]View PlainCopy
- Package com.tony.shader;
- Import Android.os.Bundle;
- Import android.app.Activity;
- Public class Mainactivity extends Activity {
- private Radialgradientview Radialgradientview;
- @Override
- protected void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Radialgradientview = New Radialgradientview (this);
- Setcontentview (Radialgradientview);
- }
- }
Radialgradientview:
[Java]View PlainCopy
- Package com.tony.shader;
- Import Android.content.Context;
- Import Android.graphics.Canvas;
- Import Android.graphics.Color;
- Import Android.graphics.Paint;
- Import android.graphics.RadialGradient;
- Import Android.graphics.Shader;
- Import Android.util.AttributeSet;
- Import Android.view.View;
- Public class Radialgradientview extends View {
- Paint mpaint = null;
- //circular gradient rendering
- Shader mradialgradient = null;
- Public Radialgradientview (context context) {
- super (context);
- //1. Center x coordinate 2.Y coordinates 3. Radius 4. Array of colors 5. Array of relative positions, nullable 6. Renderer Tiling mode
- Mradialgradient = new Radialgradient ( new int[] {
- Color.yellow, Color.green, Color.transparent, color.red}, null,
- Shader.TileMode.REPEAT);
- Mpaint = new Paint ();
- }
- Public Radialgradientview (context context, AttributeSet attrs) {
- Super (context, attrs);
- }
- @Override
- protected void OnDraw (canvas canvas) {
- //Draw a circular gradient
- Mpaint.setshader (mradialgradient);
- //First, the second parameter represents the center coordinate
- //The third parameter represents the RADIUS
- Canvas.drawcircle ( mpaint);
- }
- }
Android Color Rendering (vi) Radialgradient ring rendering