Android Question Buttons don't maintain their sizes

LucianoB

Member
Licensed User
Longtime User
Hello to everybody, I hope on someone's help for the following issue cause I'm not able to find a way to fix it.
I have some panels and some buttons of different sizes on each of them. Buttons are set as GradientDrawable, set colors and sizes in designer. Everything worked fine until I wanted to assign buttons' colors at runtime. So I use:
B4X:
Sub Globals
Dim ColGreen(2),ColRed(2), ColBlu(2) As Int
Dim sGreen,sRed, sBlu As GradientDrawable
ColRed(0) = Colors.LightGray
ColRed(1) = Colors.red
ColGreen(0)= Colors.LightGray
ColGreen(1)= Colors.RGB (9, 108, 1)
ColBlu(0) = Colors.LightGray
ColBlu(1) = Colors.Blue

sGreen.Initialize("TOP_BOTTOM", ColGreen)
sGreen.CornerRadius = 6
sRed.Initialize("TOP_BOTTOM", ColRed)
sRed.CornerRadius =6
sBlu.Initialize("TOP_BOTTOM", ColBlu)
sBlu.CornerRadius =6
End sub

Then I call a sub to assign colors and text size:
B4X:
    Button1.Background=sGreen
    Button2.Background=sGreen
    Button3.Background=sGreen
    Button4.Background=sGreen
    Button1.TextSize =18
    Button2.TextSize =18
    Button3.TextSize =18
    Button4.TextSize =18
    ......................................

The strange effect I have is shown in the attached screenshots. I show the panel in pic1 then, without closing it, I show another panel (pic2), then if I show again the first panel all buttons on it changed their sizes (pic3) taking the sizes of buttons on panel in pic2. What do I do wrong?
 

Attachments

  • pic1.png
    128.3 KB · Views: 169
  • pic2.png
    75.6 KB · Views: 153
  • pic3.png
    121.8 KB · Views: 169

LucianoB

Member
Licensed User
Longtime User
Thank you for your reply Erel.

1 - Ok. I will correct and move the code from Sub Globals.

2 - Maybe here it is my mistake: I use the same drawable for many buttons which have different sizes, as you can see from the above code. Do you agree?

3 - I will check this way too.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…