Android Question Unable to position some views at desired locations

toby

Well-Known Member
Licensed User
Longtime User
In the layout file, there are two side-by-side panels, pnlFee(left) and pnlWeekly (right). The left panel looks good enough to me after applying anchors and designer scripts.
However if I apply similar technique to the right panel, neither view would appear. Here are the designer scripts

designer scripts:
'All variants script
AutoScaleAll

'scripts for left panel:
pnlFee.SetLeftAndRight(0,50%x)
lblFee.SetLeftAndRight(pnlFee.Left+1%x, pnlFee.Right-1%x)
bpmOffer.SetLeftAndRight(pnlFee.Left+1%x, pnlFee.Right-1%x)

'scripts for right panel:'
pnlWeekly.SetLeftAndRight(49%x,99%x)
lblWeekly.SetLeftAndRight(pnlWeekly.Left+1%x, pnlWeekly.Right-1%x) 'the runtime screenshot was taken when this line was commented out.
chkWeekly.SetLeftAndRight(pnlWeekly.Left+1%x, pnlWeekly.Right-1%x)

The layout file is attached. Could someone tell me what I did incorrectly? Thank you in advance!

designer.png
runtime.jpg
 

Attachments

  • new.bal
    4.6 KB · Views: 100
Solution
Set all horizontal anchors to Left, as you set them in the code.
Then, the dimensions of views in a Panel are referred to the panel's upper left corner and not to the screen.
The code below works:

B4X:
'All variants script
AutoScaleAll

pnlFee.SetLeftAndRight(1%x,50%x)
lblFee.SetLeftAndRight(1%x, pnlFee.Width-1%x)
bpmOffer.SetLeftAndRight(1%x, pnlFee.Width-1%x)

pnlWeekly.SetLeftAndRight(51%x,99%x)
lblWeekly.SetLeftAndRight(1%x, pnlWeekly.Width-1%x)
chkWeekly.SetLeftAndRight(1%x, pnlWeekly.Width-1%x)

klaus

Expert
Licensed User
Longtime User
Set all horizontal anchors to Left, as you set them in the code.
Then, the dimensions of views in a Panel are referred to the panel's upper left corner and not to the screen.
The code below works:

B4X:
'All variants script
AutoScaleAll

pnlFee.SetLeftAndRight(1%x,50%x)
lblFee.SetLeftAndRight(1%x, pnlFee.Width-1%x)
bpmOffer.SetLeftAndRight(1%x, pnlFee.Width-1%x)

pnlWeekly.SetLeftAndRight(51%x,99%x)
lblWeekly.SetLeftAndRight(1%x, pnlWeekly.Width-1%x)
chkWeekly.SetLeftAndRight(1%x, pnlWeekly.Width-1%x)
 
Upvote 2
Solution

toby

Well-Known Member
Licensed User
Longtime User
@klaus, it works like a charm with your modified scripts! Thank you very much for saving me countless hours. You've made my day!
 
Upvote 0
Top