I have an application with a number of buttons. The layout of the buttons is set in the code to be:
B4X:
Private cdBtnBackground As ColorDrawable
Private intColorBack As Int
Private intColorBorder As Int
Private intColorText As Int
Private intBtnTextSize As Int
intColorBack = Colors.RGB(255,255,255)
intColorBorder = Colors.RGB(25,25,112)
intColorText = Colors.RGB(25,25,112)
intBtnTextSize = 14
cdBtnBackground.Initialize2(intColorBack, 5, 1, intColorBorder)
btnBest.Background = cdBtnBackground
btnBest.TextColor = intColorText
btnBest.TextSize = intBtnTextSize
so far so good (see attached picture 1). However, while using the application, buttoms start to loose the right edge without any reason (see picture 2). After a while, all buttons lost the right edge (see picture 3)...
Is this a bug? Any suggestion what i can do to avoid this?
You need to show more code, just the code snippet it is impossible to give a concrete advice.
Post a small project that shows the problem so we could have a look on what you have done..
Thanks for the hints.
1. I adapted the buttons layout in the designer, and thus no longer set the drawable in the code. As a result I don't have the problem any more ;
2. I did indeed use a single drawable for multiple buttons, which I'll retain for the future. However, I don't understand why I shouldn't...
A drawable is an object (unlike a number). It is not copied when you set it to multiple views. It means that the views share the same instance. Each view will try to change the border size based on its own dimension and it will not work properly.