Android Question The SetLeftAndRight is not related to the parent

pmt

Member
Licensed User
Hi ,

I tested designer script with simple layout have 3 objects.
-Panel_Parent (with default properties) is the first panel
-Panel_Child (with default properties) is in the Panel_Parent
-Label1 (with default properties) is in the Panel_Child

The variants is 320 x 480 ,scale = 1 (160 dpi )

Please check the first attached image.

designerscript1.jpg



Then I ran script:
B4X:
'All variants script
'AutoScaleAll
Panel_Parent.SetLeftAndRight(0,100%x)
Panel_Child.SetLeftAndRight(20,50%x)
Label1.SetLeftAndRight(0,100%x)

I expect the Label1 will be width 100% in the Panel_Child but the width oversize than Panel_Child .

Please check the second attached image

designerscript2.jpg


Is this how it work or something wrong?

Best Regards,
pmt
 

NJDude

Expert
Licensed User
Longtime User
You are doing it wrong, this line:
B4X:
Panel_Child.SetLeftAndRight(20,50%x)
You are centering it using the ACTIVITY as parent, you should use the PARENT PANEL, also, you have to use dip.

e.g.
B4X:
Panel_Child.SetLeftAndRight(20dip ,50%x)
 
Upvote 0

pmt

Member
Licensed User
You are doing it wrong, this line:
B4X:
Panel_Child.SetLeftAndRight(20,50%x)
You are centering it using the ACTIVITY as parent, you should use the PARENT PANEL, also, you have to use dip.

e.g.
B4X:
Panel_Child.SetLeftAndRight(20dip ,50%x)

Thank you for your reply NJDude.

I tried
B4X:
Panel_Child.SetLeftAndRight(20dip,50%x)
Or
B4X:
Panel_Child.SetLeftAndRight(0,50%x)

But not work , the Label1 's width still oversize than Panel_Child's width.

My point is why the Label1's width oversize than Panel_child 's width ?

Regards,
Pmt
 
Upvote 0

pmt

Member
Licensed User
Try this:
B4X:
Panel_Child.SetLeftAndRight(20dip, Panel_Parent.Width / 2)

OK , I tried.
B4X:
Panel_Child.SetLeftAndRight(0,Panel_Parent.Width/2)
Label1.SetLeftAndRight(0,Panel_Child.Width)

It 's work as I expected.


Thanks you.
Regards,
pmt
 
Upvote 0
Top