Android Question Problem with ColorDrawable

Jeff Garland

Member
Licensed User
Longtime User
I'm sure I'm doing something wrong but can't figure it out.

My app initially had rectangular buttons that looked good but I wanted a rounded look so I tried ColorDrawable. I have it set up in my code as:

Dim cdAll As ColorDrawable
cdAll.Initialize2( Colors.LightGray, 10dip, 1dip, Colors.Blue)

The problem is that when I set my buttons like "buttonClose.Background = cdAll", Some look great. Some are rounded on the left end and square on the right end. Some end up being half their original (rectangular) size.

In the designer I have them all setup like this:

delta = ((100%x + 100%y) / (320dip + 460dip) - 1)
rate = 0.1 'value between 0 to 1.
scale = 1 + rate * delta
x1 = 100%x
y1 = 100%y
x2 = 50%x
y2 = 50%y

l = 5
t = 420
w = 310
h = 40
buttonClose.Left = l/320*x1
buttonClose.Width = w/320*x1
buttonClose.Top = t/460*y1
buttonClose.Height = h/460*y1
buttonClose.SetLeftAndRight(l/320*x1,l/320*x1 + w/320*x1)
buttonClose.SetTopAndBottom(t/460*y1,t/460*y1 + h/460*y1)
buttonClose.TextSize = buttonClose.TextSize * scale

I can see no reason some would be good and others bad since they are all set up the same way and in many cases, are copies of each other.

This is version 8.80

Thanks for any help.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Try using dip values for your buttonClose left, width, top, etc... Also, use either SetLeftAndRight & SetTopAndBottom OR Left, Width, Top, Height - not both, because they do the same thing.

- Colin.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Where do you set buttonClose.Background = cdAll?
It doesn't appear in your code!
Anyway, you need to define a separate ColorDrawable for each button.
Using the same ColorDrawable for all buttons can produce unexpected behaviours.

Why do you use the code you show in the Designer?
That's exactly what AutoScale does!
 
Upvote 0

Jeff Garland

Member
Licensed User
Longtime User
Where do you set buttonClose.Background = cdAll?
It doesn't appear in your code!
Anyway, you need to define a separate ColorDrawable for each button.
Using the same ColorDrawable for all buttons can produce unexpected behaviours.

Why do you use the code you show in the Designer?
That's exactly what AutoScale does!


Yes it was in the text at the top : "The problem is that when I set my buttons like "buttonClose.Background = cdAll"

I wrote this code originally a long while back. Before autoscale was available or at least before I new it was. I have been using B4A since version one I think and don't want to have to rewrite this too much when new features come out if what I have worked. It did until I tried colordrawable.

Ahh, I will certainly create a separate drawable for the others. I wondered why there seemed to be cross feed. In this case they will all be the same cause i want the same look but I can certainly do that.

Thanks!
 
Upvote 0

Jeff Garland

Member
Licensed User
Longtime User
Nope. I made separate colordrawables for each screen. Each screen has 1, 2 or 3 buttons on it typically. That means that each colordrawable may have 1, 2 or 3 buttons. The ones that were good before still are, the ones that were chopped off before still are. I'm going through now and making a colordrawable for each button but so far that has no better impact either.
 
Upvote 0

Jeff Garland

Member
Licensed User
Longtime User
OK so I went through and made separate colordrawables for each button that was screwed up and now it looks good.

Thanks for the help.
 
Upvote 0
Top