Android Question Why it's true in designer but wrong in phone and simulator?

vhd_bgh

Member
Hi
I used two button in a panel with this script code:
B4X:
'All variants script
'AutoScaleAll
Button1.Width = Panel1.Width/2
Button2.Width = Panel1.Width/2
it's true in designer:
2020-05-15 17_09_57-1 - (ljk) Visual Designer.png


but... why it's wrong in simulator and phone?
2020-05-15 17_09_46-NoxPlayer.png


what code should I use for this?
 
Last edited:

udg

Expert
Licensed User
Longtime User
Are you sure that setting both labels' horizontal anchors to BOTH is valid?
AFAIK, just one view on a row can have BOTH as its horizontal anchor setting.
Same for vertical setting.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
udg, I agree with you. Setting the horizontal anchor to BOTH on the two Labels will not work!
The only way is the code suggested in post #2.
Why?
In the layout in post #1. the anchors of the two Buttons are LEFT for the left one and RIGHT for the right one.
In the original layout both Buttons cover the whole width of the Panel which has the horizontal anchor set to BOTH.
Then, if the width of the final Panel is wider than the original one the right Button is anchored to the right edge of the Panel, leaving a space between the two Buttons.
Then when you set the width of the Buttons, in the Designer Script, to half the Panel width, it's OK for the left one but not for the right one.
Why? Because, when you set the width of a view, its reference is the Left property.
The anchors are set before the Designer Script code is executed. Therefore the Designer Script doesn't take into account the anchors anymore.
 
Upvote 0

vhd_bgh

Member
udg, I agree with you. Setting the horizontal anchor to BOTH on the two Labels will not work!
The only way is the code suggested in post #2.
Why?
In the layout in post #1. the anchors of the two Buttons are LEFT for the left one and RIGHT for the right one.
In the original layout both Buttons cover the whole width of the Panel which has the horizontal anchor set to BOTH.
Then, if the width of the final Panel is wider than the original one the right Button is anchored to the right edge of the Panel, leaving a space between the two Buttons.
Then when you set the width of the Buttons, in the Designer Script, to half the Panel width, it's OK for the left one but not for the right one.
Why? Because, when you set the width of a view, its reference is the Left property.
The anchors are set before the Designer Script code is executed. Therefore the Designer Script doesn't take into account the anchors anymore.
klaus, I agree with you too. (according to Erel teaches in "Visual designer ")
but in this case (#1) it's not rational and I couldn't figure out why?!?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Then when you set the width of the Buttons, in the Designer Script, to half the Panel width, it's OK for the left one but not for the right one.
Why? Because, when you set the width of a view, its reference is the Left property.
This is pure gold! Clear, complete and right on the point. Great. Should be emphasized everywhere Designer rules are explained.
 
Upvote 0
Top