Android Color Rendering (vi) Radialgradient ring rendering

Source: Internet
Author: User

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


Radialgradientview:

[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.Paint;
    6. Import android.graphics.RadialGradient;
    7. Import Android.graphics.Shader;
    8. Import Android.util.AttributeSet;
    9. Import Android.view.View;
    10. Public class Radialgradientview extends View {
    11. Paint mpaint = null;
    12. //circular gradient rendering
    13. Shader mradialgradient = null;
    14. Public Radialgradientview (context context) {
    15. super (context);
    16. //1. Center x coordinate 2.Y coordinates 3. Radius 4. Array of colors 5. Array of relative positions, nullable 6. Renderer Tiling mode
    17. Mradialgradient = new Radialgradient ( new int[] {
    18. Color.yellow, Color.green, Color.transparent, color.red}, null,
    19. Shader.TileMode.REPEAT);
    20. Mpaint = new Paint ();
    21. }
    22. Public Radialgradientview (context context, AttributeSet attrs) {
    23. Super (context, attrs);
    24. }
    25. @Override
    26. protected void OnDraw (canvas canvas) {
    27. //Draw a circular gradient
    28. Mpaint.setshader (mradialgradient);
    29. //First, the second parameter represents the center coordinate
    30. //The third parameter represents the RADIUS
    31. Canvas.drawcircle ( mpaint);
    32. }
    33. }

Android Color Rendering (vi) Radialgradient ring 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.