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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:18:17+00:00 2026-06-14T08:18:17+00:00

First Q. I have working code to make this move elsewhere in the file

  • 0

First Q. I have working code to make this move elsewhere in the file — that’s not the question. The question is how do I create a Radial Gradient that can be moved (below API 16).

Preempting snark, I’ve spent a lot of time here:

http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html

With GradientDrawable (below), there doesn’t seem to be a way to set the colors without also setting a non-radial orientation.

public class CustomView extends View {
    int width = (sWidth/8); // sWidth defined elsewhere as width of screen
    int height = (sWidth/8);
    GradientDrawable gradient;
    int[] colors = {0x60ffffff,0x000000};

    public CustomView(Context context) {
        super(context);
        gradient = new GradientDrawable(GradientDrawable.Orientation.BL_TR,colors);
    }

    protected void onDraw(Canvas canvas) {
        if(x != 0 && y != 0){ // OnTouch calls invalidate on this view for movement
            gradient.mutate();
            gradient.setShape(GradientDrawable.RADIAL_GRADIENT);
         // This just makes it disappear:
         // setGradientType (GradientDrawable.RADIAL_GRADIENT);
            gradient.setBounds(x-width/2, y-height/2, x + width, y + height);
            gradient.draw(canvas);
        }
    }
}

There is also this:

http://developer.android.com/reference/android/graphics/RadialGradient.html

But there seems to be no way to move that gradient. Can you maybe put the radial gradient on a transparent circle of some kind that can then be moved? I’m at a loss. My thanks in advance.

  • 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-14T08:18:18+00:00Added an answer on June 14, 2026 at 8:18 am

    Edit:

    Step 1, define an oval shape in your drawable folder. This one is “cloud.xml”:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    
    <gradient
        android:centerX="0.5"
        android:centerY="0.5"
        android:endColor="#00000000"
        android:gradientRadius="30"
        android:startColor="#f0ffffff"
        android:type="radial" />
    <size
        android:width="60dp"
        android:height="60dp" />
     </shape>
    

    The radius, width and height will likely need to be changed dynamically. So put whatever. The color scheme above will give a slightly transparent color to fully transparent. Cloud effect.

    Step 2, the constructor of your custom view:

    // actually before the constructor this, of course:
    GradientDrawable circle;
    
    // now the constructor:
    
    circle = (GradientDrawable) context.getResources().getDrawable(R.drawable.cloud);
    

    Step 3, the onDraw method:

                // x & y being coordinates updated from onTouch method,
                // circleRad being some constant dependent on screen dp
                if(x != 0 && y != 0){
                circle.setGradientRadius(circleRad);
                circle.setBounds(x-circleRad, y-circleRad,
                        x+circleRad, y+circleRad);
                circle.draw(canvas);
            }
    

    ————- Original, Less Process Efficient Solution Preserved Below ———–

    Wait a couple weeks and you can answer your own questions. Turns out it was RadialGradient the whole time.

    public class CustomView extends View implements OnTouchListener {
        Shader radialGradientShader;
        Paint paint;
        private int circleDiam;
        private int x = 0;
        private int y = 0;
        private int lastScreenColor;
    
        public CustomView(Context context, int circleDiam) {
            super(context);
            this.circleDiam = circleDiam;
            paint = new Paint();
        }
    
        protected void onDraw(Canvas canvas) {
            if(x != 0 && y != 0){       
                paint.setStyle(Paint.Style.FILL);
                paint.setAntiAlias(true);
                radialGradientShader = new
        RadialGradient(x, y, circleDiam,
        0xf0ffffff,0x00000000,Shader.TileMode.MIRROR);
                paint.setShader(radialGradientShader);
                canvas.drawCircle(x, y, circleDiam, paint);
            }
        }
    
        public boolean onTouch(View v, MotionEvent event) {
            x = (int)event.getX();
            y = (int)event.getY();
    
            if(event.getAction() == MotionEvent.ACTION_DOWN 
         && event.getAction() == MotionEvent.ACTION_MOVE){
                invalidate();
                return true;
            }
            else{ 
                x = 0;
                y = 0;
                invalidate();
                return false;
            }
        }
    }
    

    A fluffy cloud!

    The only problem with this solution is that Eclipse gets mad when you instantiate an object in the onDraw method. However, if you try to instantiate it in the constructor things get ugly fast.

    Extra points for a solution that avoids said problem.

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

Sidebar

Related Questions

First off I should say that I don't have any experience in working with
I have this working code f = SomeForm(request.POST) When I tried to modify it
i'm trying to make this code snippet from the sinatra tutorial work so that
I have been working on this code for hours and I cant seem to
I'm using Entity Framework Code First and whilst I have working code, I'm having
Below is a file iterarot unction I have working on that iterates over folders
I have been working on building my first CSS site using divs and am
I am new to wpf and i am working on first application i have
I'm working on my first game and I have a little over 20 classes.
I have a problem but first i want to know if im working on

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.