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

Discussion in 'Android Questions' started by Cableguy, Jun 5, 2015.

  1. Cableguy

    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?
     
  2. Cableguy

    Cableguy Expert Licensed User

    No one?
     
  3. RandomCoder

    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?
     
    Peter Simpson likes this.
  4. Cableguy

    Cableguy Expert Licensed User

    Its an idea... I could load that from the .them file...
     
  5. Enrique Gonzalez R

    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)
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You can use this code to get these values for views with ColorDrawable background.
    Code:
    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
     
    Peter Simpson and Cableguy like this.
  7. Cableguy

    Cableguy Expert Licensed User

    Thanks Erel!

    One question, why do you need to check the view type?
     
    Last edited: Jun 7, 2015
  8. Cableguy

    Cableguy Expert Licensed User

    using your example I was able to also retrieve the border color value... any chance to also retrieve background color??
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    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.
     
  10. Cableguy

    Cableguy Expert Licensed User

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