Android Question Designer Script Help

Stichler

Active Member
Licensed User
Ok essentially I have code that finds the devices width and height defined as :
pScreenWidth
pScreenHeight

Now if possible I want to take Panel1 and set it to match those numbers.
I've tried using this code in Designer Scripts with no luck:

Panel1.Width = pScreenWidth
Panel1.Height = pScreenHeight

it does not work. Is what I'm attempting impossible? Should it be done in the Module?

Very sorry for all my newb like questions, but you gotta learn somewhere, somehow!
 

Stichler

Active Member
Licensed User
I'm very confused because if I add an Image with no Panel and select Fill it perfectly fits device full screen and width, but no fill option for panels. I'm frustrated lol
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Stich.... Just setting the height and width in code will not fill the screen, simply make the panel the same size as the screen centering it 'who knows where'?

In the script:
B4X:
Panel1.SetLeftAndRight(0,100%x)
Panel1.SetTopAndBottom(0,100%y)
 
Upvote 0

Stichler

Active Member
Licensed User
Ahh ty! Now lets say I want a button in the middle of that panel and want it to be in the middle of any device that would use the app. What would be best way to go about that?
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
In the designer there are properties you can use to center the control:
B4X:
btnExit.HorizontalCenter=50%x
btnExit.VerticalCenter=50%y

If you wish to center it within the panel, then use the containing panel dimensions:
B4X:
btnExit.Left = (panel1.Width - btnExit.Width) / 2
btnExit.Top = (panel1.Height - btnExit.Height) / 2
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Instead of
B4X:
Panel1.SetLeftAndRight(0,100%x)
Panel1.SetTopAndBottom(0,100%y)
You can adjust the Panel to fill the screen and set the anchors to both.

upload_2018-8-10_7-53-56.png


You may also have a look at the B4X Booklets.
 
Upvote 0
Top