Android Question an odd one... how can I GET a views corner radius?

Cableguy

Expert
Licensed User
well, I guess the title says it all...

How can I get a views corner radius?

and while I'm at it, how to get the border thickness?
 

RandomCoder

Well-Known Member
Licensed User
Sorry pal no ideas this time, but if you are setting the view in the first place then maybe you can store the values that were used to create the view to use later as required? Just an idea if it's a view that is created in code?
 

Enrique Gonzalez R

Well-Known Member
Licensed User
Assign an id (with tag) to the view, create a map an store the view Id as a key and the corner radius as value.

After that is just imagination with map.get(view.tag)
 

Erel

Administrator
Staff member
Licensed User
You can use this code to get these values for views with ColorDrawable background.
B4X:
If GetType(Label1.Background) = "anywheresoftware.b4a.objects.drawable.ColorDrawable$GradientDrawableWithCorners" Then
   Dim cd As ColorDrawable = Label1.Background
   Dim jo As JavaObject = cd
   Log($"Radius = ${jo.GetField("cornerRadius")}, BorderWidth = ${jo.GetField("borderWidth")}"$)
End If
 

Cableguy

Expert
Licensed User
Thanks Erel!

One question, why do you need to check the view type?
 
Last edited:

Cableguy

Expert
Licensed User
using your example I was able to also retrieve the border color value... any chance to also retrieve background color??
 

Erel

Administrator
Staff member
Licensed User
One question, why do you need to check the view type?
We are checking the view's background type. It can be a different type if for example you use GradientDrawable in the designer.

It is more difficult to get the background color due to the way it is saved. Will be easier to use the Tag property for this.
 

Cableguy

Expert
Licensed User
I'm using bitmap and canvas to get the background color as suggested in another thread. Thanks Erel
 
Top