Android Question GradientDrawable with different corner radius?

Discussion in 'Android Questions' started by welu1805, Mar 5, 2015.

  1. welu1805

    welu1805 Active Member Licensed User

    In "TabHostExtras1.setTabGradientDrawable2" I can set the corner radius for the GradientDrawable like described below:

    "Set a GradientDrawable as the background on all TabIndicators in tabHost1
    Corner radii of the GradientDrawable are set individually (in pixels) based upon the number of elements in the array cornerRadius:
    1 element defines all corner radii
    2 elements define corner radii in order top left and right, bottom left and right
    4 elements define corner radii in order top-left, top-right, bottom-right, bottom-left"

    How can I set different Corner Radii for a GradientDrawable?
     
  2. klaus

    klaus Expert Licensed User

    You can do it with the JavaObject library.
    Code:
    Sub setCornerRadii(v As View, Rx_TopLeft As Float, Ry_TopLeft As Float, Rx_TopRight As Float, Ry_TopRight As Float, Rx_BottomRight As Float, Ry_BottomRight As Float, Rx_BottomLeft As Float, Ry_BottomLeft As Float)
        
    Dim jo As JavaObject = v.Background
        
    If v.Background Is ColorDrawable OR v.Background Is GradientDrawable Then
            jo.RunMethod(
    "setCornerRadii"Array As Object(Array As Float(Rx_TopLeft, Ry_TopLeft, Rx_TopRight, Ry_TopRight, Rx_BottomRight, Ry_BottomRight, Rx_BottomLeft, Ry_BottomLeft)))
        
    End If
    End Sub
    It's possible for ColorDrawable and GradientDrawable backgrounds.
    8 parameters are needed, two for each corner.
    In the routine above you submit the view to change and the routine checks if the backgrounds ColorDrawables or GradientDrawables.
     
    Ivan Aldaz and jimmyF like this.
  3. welu1805

    welu1805 Active Member Licensed User

    It works good.
    Thank you, Klaus.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice