Android Question Buttons not filling with BackgroundImage

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

It appears that buttons have a default transparent edge of a few pixels when using backgroundImage. The result is that when you place buttons edge to edge there is a gap that shows what is behind the buttons.
Does anyone know how to have the image completely fill the button?

Regards Roger


B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim Buttons(8, 8) As Button
   Dim ButtonViews(8,8)
   Dim Tile As Bitmap
   Dim Background As ImageView


Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("Portrait")
 
    Dim width, height As Int
    width = 12.5%x
    height = width
    Tile.Initialize ( File.DirAssets , "Tile.png")

    For x = 0 To 7
        For y = 0 To 7
            Dim btn As Button
            btn.Initialize("button")             'All buttons share the same event sub
            btn.SetBackgroundImage(Tile)
            btn.Gravity = Gravity.FILL
            Activity.AddView(btn, x * width, y * height, width , height)
            Buttons(x, y) = btn                 'store a reference to this view
        Next
    Next
 
    For Each v As View In Activity.GetAllViewsRecursive
        If v Is Button Then
             Dim jo As JavaObject = v
             jo.RunMethod("setPadding", Array As Object(0, 0, 0, 0))
        End If
       If v Is EditText Then
             Dim jo As JavaObject = v
             jo.RunMethod("setPadding", Array As Object(0, 0, 0, 0))
       End If
       If v Is Label Then
             Dim jo As JavaObject = v
             jo.RunMethod("setPadding", Array As Object(0, 0, 0, 0))
       End If
    Next

End Sub



Atoms.jpg
 
Last edited:

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi Erel,

Much embarrassment on my part. I have found the gap is caused by the bitmap "Tile.png". When I used Gimp to add the black border Gimp also added a transparent border beyond that. ???

I guess this enters me in the "Dumbest Question of the Week" competition. Sorry for the trouble.


Regards Roger
 
Upvote 0
Top