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

Cableguy

Expert
Licensed User
Longtime 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?
 

Cableguy

Expert
Licensed User
Longtime User
No one?
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime 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?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Its an idea... I could load that from the .them file...
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime 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)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Thanks Erel!

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

Cableguy

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

Erel

B4X founder
Staff member
Licensed User
Longtime 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.
 
Upvote 0

Cableguy

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