Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6682923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:45:42+00:00 2026-05-26T04:45:42+00:00

in Android I would like to draw a PieChart with a dynamically number of

  • 0

in Android I would like to draw a PieChart with a dynamically number of pies. Each pie should have a different color from a gradient.

For example I would like to have a gradient from light brown to dark brown. If I need to draw five pies, I need five volors from the start to the end of this gradient.

How can I do that in Java with the Android framework?

I found out that I can create a LinearGradient for a line, i.e.:

LinearGradient lg = new LinearGradient(1, 1, 5, 5, toRGB("lightbrown"), toRGB("darkbrown"), TileMode.REPEAT);

But I did not found any function to get a color from this line, i.e.:

// for the five needed RGB colors from the gradient line
lg.getRGBColor(1, 1);
lg.getRGBColor(2, 2);
lg.getRGBColor(3, 3);
lg.getRGBColor(4, 4);
lg.getRGBColor(5, 5);

Do you have any ideas how I can get this?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:45:43+00:00Added an answer on May 26, 2026 at 4:45 am

    You cannot get these values directly from the LinearGradient. The gradient doesn’t contain the actual drawing. To get these values, you can paint them to a canvas and pull the colors out of the canvas, or what I’d suggest would be to calculate the values yourself.

    It’s a repeating linear gradient in five steps and you have the RGB values for the first and last color. The rest is just math. Here’s the pseudo code:

    int r1 = startColor.red;
    int g1 = startColor.green;
    int b1 = startColor.blue;
    
    int r2 = endColor.red;
    int g2 = endColor.green;
    int b2 = endColor.blue;
    
    int redStep = r2 - r1 / 4;
    int greenStep = g2 - g1 / 4;
    int blueStep = b2 - b1 / 4;
    
    firstColor = new Color(r1, g1, b1);
    secondColor = new Color(r1 + redStep, g1 + greenStep, b1 + blueStep);
    thirdColor = new Color(r1 + redStep * 2, g1 + greenStep * 2, b1 + blueStep * 2);
    fourthColor = new Color(r1 + redStep * 3, g1 + greenStep * 3, b1 + blueStep * 3);
    fifthColor = new Color(r1 + redStep * 4, g1 + greenStep * 4, b1 + blueStep * 4);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i would like to buy a new cell phone that runs Android. From what
I would like my Android application to react to an incoming email from specific
I would like to have a fake android account I can use for testing
I am writing and publishing my apps on android and would like to provide
For Android GUI: I would like to create a window that I can pull
I would like to run APIDemos under platforms\android-1.5\samples directory on Android emulator but I
I would like to create a custom control in my Android App. It will
I would like to do two things within my Android app : Check if
I would like to know whether this is actually possible in Android? When Android
I would like to invoke a webservice via Android. I need to POST some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.