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 8041351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:11:11+00:00 2026-06-05T04:11:11+00:00

I’m trying to make a color picker that allows the users to pick color

  • 0

I’m trying to make a color picker that allows the users to pick color by simply having a touch input. My hueShade gives the hue to the color circle, while the saturationShade gives
me the whiting out of the center. The SweepGradient does not need a radius, but the Radial Gradient does require it. However, I am calling this at the time of the creation when it can’t get the actual values of the width and height. Instead it picks up the values stated. Is there an intermediate step where the radius can be set when that information is available? Or should I try a different approach?

private Paint mPaint;
private int[] mColors;

private int viewWidth = 120;
private int viewHeight = 120;
private int centerX = 60;
private int centerY = 60;
private int padding = 10;

public ColorWheelView(Context context) {
    super(context);
    onInitialize();
    // TODO Auto-generated constructor stub
}


private void onInitialize()
{

    mColors = new int[] {
            0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00,
            0xFFFFFF00, 0xFFFF0000
        };

        Shader totalShade = new SweepGradient(0, 0, mColors, null);
        Shader hueShade = new SweepGradient(0, 0, mColors, null);
        Shader saturationShade = new RadialGradient(0, 0, (float)viewWidth-padding, 0xFFFFFFFF, 0x00FFFFFF, Shader.TileMode.CLAMP);
        //Shader valueShade;

        totalShade = new ComposeShader(hueShade, saturationShade, PorterDuff.Mode.SCREEN);

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setShader(totalShade);
        mPaint.setStyle(Paint.Style.FILL);
}

protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld) 
{
    super.onSizeChanged(xNew, yNew, xOld, yOld);
    viewWidth = xNew;
    viewHeight = yNew;
    centerX = viewWidth / 2;
    centerY = viewHeight / 2;
}

protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
    super.onLayout(changed, left, top, right, bottom);
    viewWidth = right - left;
    viewHeight = bottom - top;
    centerX = viewWidth / 2;
    centerY = viewHeight / 2;
}

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int measuredHeight = measureHeight(heightMeasureSpec);
    int measuredWidth = measureWidth(widthMeasureSpec);
    setMeasuredDimension(measuredWidth, measuredHeight);
}

If it helps to figure out what I am achieving, I’m trying to make this view available to use for different size screens. That’s why I need the information from the device.

  • 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-06-05T04:11:13+00:00Added an answer on June 5, 2026 at 4:11 am

    It is best to call this in onLayout since it’s typically guaranteed when any change in size or orientation is performed. I wasn’t getting desired values previously, but that was because I inherited from a base class other than the Android.view.View class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

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.