Missing: Gradient Radial Fill

Widget

Well-Known Member
Licensed User
Longtime User
The GradientDrawable is missing Radial fill, where the fill is like a starburst radiating from the center. This will give buttons etc. more of a 3D effect. Other HTML products I've used will also let you specify the location of the center of the radial (and linear fills to). Example: at 10,10 from the top of the image.

I don't know why Radial fill is missing, maybe it is an Android limitation?

Widget

See Gradient Radial Fill Example
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can do it with the help of the Reflection library:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim GD As GradientDrawable
    GD.Initialize("TOP_BOTTOM", Array As Int(Colors.White, Colors.Black))
    activity.Background = gd
    SetRadialGradient(GD, Activity.Height/2)
End Sub

Sub SetRadialGradient(GD As GradientDrawable, radius As Float)
    Dim r As Reflector
    r.Target = GD
    r.RunMethod2("setGradientType", 1, "java.lang.int")
    r.RunMethod2("setGradientRadius", radius, "java.lang.float")
End Sub
 

moster67

Expert
Licensed User
Longtime User
Wow....there are so much hidden information here in the forum.
This tip should be added to the manual here:

Basic4android - Drawing (Core)


You can do it with the help of the Reflection library:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim GD As GradientDrawable
    GD.Initialize("TOP_BOTTOM", Array As Int(Colors.White, Colors.Black))
    activity.Background = gd
    SetRadialGradient(GD, Activity.Height/2)
End Sub

Sub SetRadialGradient(GD As GradientDrawable, radius As Float)
    Dim r As Reflector
    r.Target = GD
    r.RunMethod2("setGradientType", 1, "java.lang.int")
    r.RunMethod2("setGradientRadius", radius, "java.lang.float")
End Sub
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Is there a way to do a circle-shaped gradient where it starts at one angle+color, and sweeps towards a second angle+color?
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
That uses more trigonometry than what can run in real time at a high framefrate.
It was the first thing I considered.

Right now I'm using a linear gradient, simply rotated to match the inner point. Then clipped using ExDraw to a slice of the circle.
It's not perfect, but close.
 

derez

Expert
Licensed User
Longtime User
If you can prepare the drawables in advance and just use the appropriate one in real time then there is no problem of prepration time.
 
Top