Android Color Rendering (v) lineargradient linear rendering

Source: Internet
Author: User

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
  1. Package com.tony.shader;
  2. Import Android.os.Bundle;
  3. Import android.app.Activity;
  4. Public class Mainactivity extends Activity {
  5. private Lineargradientview Lineargradientview;
  6. @Override
  7. protected void OnCreate (Bundle savedinstancestate) {
  8. super.oncreate (savedinstancestate);
  9. Lineargradientview = New Lineargradientview (this);
  10. Setcontentview (Lineargradientview);
  11. }
  12. }


Lineargradientview;

[Java]View PlainCopy
    1. Package com.tony.shader;
    2. Import Android.content.Context;
    3. Import Android.graphics.Canvas;
    4. Import Android.graphics.Color;
    5. Import android.graphics.LinearGradient;
    6. Import Android.graphics.Paint;
    7. Import Android.util.AttributeSet;
    8. Import Android.graphics.Shader;
    9. Import Android.view.View;
    10. Public class Lineargradientview extends View {
    11. private LinearGradient lineargradient = null;
    12. Private Paint paint = null;
    13. Public Lineargradientview (context context)
    14. {
    15. super (context);
    16. LinearGradient = New LinearGradient (0, 0, + , + , new int[] {
    17. Color.yellow, Color.green, Color.transparent, color.white}, null,
    18. Shader.TileMode.REPEAT);
    19. Paint = new paint ();
    20. }
    21. Public Lineargradientview (context context, AttributeSet attrs) {
    22. Super (context, attrs);
    23. }
    24. @Override
    25. protected void OnDraw (canvas canvas) {
    26. //TODO auto-generated method stub
    27. Super.ondraw (canvas);
    28. //Set renderer
    29. Paint.setshader (lineargradient);
    30. //Draw a circle
    31. Canvas.drawcircle (A, N, a, a, paint);
    32. }
    33. }

Android Color Rendering (v) lineargradient linear rendering

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.