Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android color Processing (v) lineargradient linear rendering
Believe that many people have seen the lyrics synchronization effect, one is the vertical direction of the scroll, on the other hand is the level of the lyrics color gradient lighting effect, how to do this effect? This requires the use of lineargradient linear rendering, the following is the first to see the specific use:
LinearGradient has two constructors;
Public lineargradient(float x0, float y0, float x1, float y1, int[] colors, float[) Positions,shader.tilemode tile )
Parameters:
Float x0: Gradient start point x coordinate
Float y0: Gradient start point y coordinate
Float x1: Gradient end point x coordinate
Float y1: Gradient end point Y coordinate
int[] Colors: int array of colors
Float[] Positions: An array of colors relative to the position, nullable, NULL, nullable, and the color evenly spaced along the gradient line
Shader.tilemode tile: Renderer tiling mode
public lineargradient(float x0, float y0, float x1, float y1, int color0, int color1,shader.tilemode tile)
float x0: Gradient start point x coordinate
float y0: gradient start point y coordinate
float x1: gradient end point x coordinate
float y1: Gradient end point Y coordinate
int color0: Starting gradient
int Color1: End Gradient Color
Shader.tilemode tile: Renderer tiling mode
:
Then look at how to achieve this effect;
Mainactivity:
[Java]View PlainCopy
- Package com.tony.shader;
- Import Android.os.Bundle;
- Import android.app.Activity;
- Public class Mainactivity extends Activity {
- private Lineargradientview Lineargradientview;
- @Override
- protected void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Lineargradientview = New Lineargradientview (this);
- Setcontentview (Lineargradientview);
- }
- }
Lineargradientview;
[Java]View PlainCopy
- Package com.tony.shader;
- Import Android.content.Context;
- Import Android.graphics.Canvas;
- Import Android.graphics.Color;
- Import android.graphics.LinearGradient;
- Import Android.graphics.Paint;
- Import Android.util.AttributeSet;
- Import Android.graphics.Shader;
- Import Android.view.View;
- Public class Lineargradientview extends View {
- private LinearGradient lineargradient = null;
- Private Paint paint = null;
- Public Lineargradientview (context context)
- {
- super (context);
- LinearGradient = New LinearGradient (0, 0, + , + , new int[] {
- Color.yellow, Color.green, Color.transparent, color.white}, null,
- Shader.TileMode.REPEAT);
- Paint = new paint ();
- }
- Public Lineargradientview (context context, AttributeSet attrs) {
- Super (context, attrs);
- }
- @Override
- protected void OnDraw (canvas canvas) {
- //TODO auto-generated method stub
- Super.ondraw (canvas);
- //Set renderer
- Paint.setshader (lineargradient);
- //Draw a circle
- Canvas.drawcircle (A, N, a, a, paint);
- }
- }
Android Color Rendering (v) lineargradient linear rendering