Bug? Size of button changing when hidden

Sam H

Member
Licensed User
Longtime User
I recently changed all the buttons in my app, to have a ".background = aGradientDrawable" property, instead of using ".color = Colors.Blue", so that my buttons could have rounded edges. However, now when a button's visibility is changed to "false" and then "true" again. The button will be a different size. Here is an example of my code:


Sub Process_Globals

End Sub

Sub Globals

Dim SelectButton As Button
Dim BackFromSelect As Button
Dim ButtonGradient As GradientDrawable

End Sub

Sub Activity_Create(FirstTime As Boolean)


Dim colours(2) As Int
colours(0) = Colors.RGB(255,165,0)
'colours(1) = Colors.RGB(255,255,255)
colours(0) = Colors.Red
colours(1) = Colors.Green

ButtonGradient.Initialize("RIGHT_LEFT", colours)
ButtonGradient.CornerRadius = 10dip



SelectButton.Initialize("SelectButton")
SelectButton.Text = "Select a Json file on the device"
SelectButton.TextSize = 14
SelectButton.TextColor = Colors.Blue
SelectButton.Background = ButtonGradient





Activity.AddView(SelectButton, 10%x, 30%y, 60%x, 15%y)


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SelectButton_Click

BackFromSelect.Initialize("BackFromSelect")
BackFromSelect.Text = "Back"
BackFromSelect.TextColor = Colors.Green
BackFromSelect.Visible = True
BackFromSelect.TextSize = 14
BackFromSelect.Background = ButtonGradient

Activity.AddView(BackFromSelect, 80%x, 0, 20%x, 10%y)

SelectButton.Visible = False

End Sub

Sub BackFromSelect_Click

SelectButton.Visible = True
BackFromSelect.Visible = False

End Sub


'Thanks In Advance

'Sam
 

Sam H

Member
Licensed User
Longtime User
You have two buttons with different sizes but you set the same background to them.
You need to define ButtonGradient two times (Dim, Initialize etc) as separate background objects one for each button.

Ok thanks, I had no idea setting the background property of the button could affect the shape of the button.

Thanks for such a quick responce.

Sam
 
Top