iOS Question Programatically re-position components

rfresh

Well-Known Member
Licensed User
Longtime User
I'm developing for my iPad. The code below tells me my screen size is 1024x768. When I try to set my Label1.Top property to 900 to position it near the lower part of the screen, the label wants to stay up towards the top of the screen where it falls by default from the Designer.

How do I programatically re-position my components?

B4X:
    pScreenHeight = GetDeviceLayoutValues.Height
    pScreenWidth = GetDeviceLayoutValues.Width
    Log(pScreenHeight)'1024
    Log(pScreenWidth)'768
    Label1.Top = 900
 

yfleury

Active Member
Licensed User
Longtime User
your label is in a panel? Make sure your panel height is set to label.top+label.height
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Hmmm...no, my label is not in a panel. I just added a label by itself in the Designer. Should I first add a panel before I start to add buttons and labels?
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
OK, I've added a Panel to my project via the Designer. I set the horizontal and vertical anchors to <--> for each. Yet the panel doesn't fill to fit my iPad screen.

What am I doing wrong?

Please see attachment.
 

Attachments

  • IMG_0055.PNG
    IMG_0055.PNG
    65.1 KB · Views: 124
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
Try this in that sub
B4X:
Private Sub Page1_Resize(Width As Int, Height As Int)
    Panel1.Width=Width
    Panel1.Height=Height
End Sub
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
That worked...mostly...I had to add the .Left and .Top properties to completely fill the iPad screen app area. Without those two lines, there was a 1/4 inch white vertical and horizontal area to the left and above the Panel1. The Panel1 looked like it was positioned, by default, at .Left 50 and .Top 50 so I just set those propertiesto 0 and that brought the Panel back over to the left and up, to cover the app screen area fully.

B4X:
    Panel1.Left = 0
    Panel1.Top = 0

So next I added a Button1 to the Panel1 in the Designer (as shown in the attachment) but when I run the app, I don't see the Button1 at all. I see it on the iPad when I'm in the edit mode via the bridge, but not when I run it in debug mode. The second attachment is what I see when I'm in design mode.

What I'm trying to do is position the button near the bottom left of the Panel but I can't even start to do that until I can see the Button!!!

B4X:
Private Sub Application_Start (Nav As NavigationController)
    'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
    NavControl = Nav
    Page1.Initialize("Page1")
    'Page1.Title = "Page Test"
    Page1.RootPanel.Color = Colors.Cyan
    NavControl.ShowPage(Page1)
   
    Page1.RootPanel.LoadLayout("Main")
    Page1.Title = "Button Label Test"

    pScreenHeight = GetDeviceLayoutValues.Height
    pScreenWidth = GetDeviceLayoutValues.Width
    'Log(pScreenHeight)
    'Log(pScreenWidth)

End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
    Panel1.Left = 0
    Panel1.Top = 0
    Panel1.Width=Width
    Panel1.Height=Height
   
End Sub
 

Attachments

  • 2018-12-28_212129.png
    2018-12-28_212129.png
    34.4 KB · Views: 121
  • IMG_0056.PNG
    IMG_0056.PNG
    62.4 KB · Views: 124
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
use Vertical anchor (arrow pointing to buttom) and place the button where you want in panel (near buttom)
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Using the Anchors in the Designer does position the Button, but the lowest position the arrow pointing down positions it to is about 50% of the way down, so it's in the middle of the iPad screen.

However, I want to be able to position it in code, but setting it's .Top property in code has no effort on positioning it.

I'm missing something here. I should be able to position a Button in code.
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
B4X:
Private Sub Page1_Resize(Width As Int, Height As Int)
    Panel1.Width=Width
    Panel1.Height=Height
    'Positionning button Without designer you have to calculate
    Button1.Top = Panel1.Height-Button1.Height-5dip
End Sub
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
I see. I was trying to position in the App Start event. So I have to do that in the Page Resize event.

Thank you...
 
Upvote 0
Top