iOS Question B4XSwitch position changing

abarnett

Member
Licensed User
Longtime User
I am trying to change the b4xSwitch left and top position using b4xSwitch.mBase.Left & b4xSwitch.mBase.Top but despite the code being executed it does not always move on the screen. I have even tried placing it inside a panel but same effect.
 

abarnett

Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
    Private chkGeofence1 As B4XSwitch
End Sub
Private Sub Application_Start (Nav As NavigationController)
    MainPage.Initialize("PageMap")
    MainPage.RootPanel.Color = Colors.White
    MainPage.RootPanel.LoadLayout("main")
    MainPage.Title = "Products - Map"
    Starter.Initialize
    chkGeoFence1.mBase.Top = 5
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What size is the Panel?
As chkGeofence1 is a child of customview-B4XSwitch, when you change chkGeofence1.Top, the Top value is referenced according to the parent panels upper left corner.
If customview-B4XSwitch has the dimensions of chkGeofence1, then you should change customview-B4XSwitch.Top.

Again without knowing exactly what you have done, in detail, we need to guess it.
 
Upvote 0

abarnett

Member
Licensed User
Longtime User
unfortunately from within the code there is no property for chkGeofence1.Top it is only accessible from chkGeofence1.mBase.Top.

I have positioned it in the layout but when the layout is drawn it has moved and so i am trying to force it back to the correct position in code.
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
Do you have 'Handle Resize Event' in false in Visual Designer?, Did you try put the code in Resize?
B4X:
Private Sub page1_Resize (Width As Float, Height As Float)
chkGeoFence1.mBase.Top = 5
End Sub
 
Upvote 0

abarnett

Member
Licensed User
Longtime User
Thank you. Yes the Handle Resize Event is False. It does not work first time the applications loads the layout but subsequent refresh the same code works fine. Putting into a resize event clears the problem.
 
Upvote 0

abarnett

Member
Licensed User
Longtime User
I do not want to move the items. When the layout first loads in the app, they have moved from the layout position. Image 1 is after the app has loaded, image 2 is after a page resize event. The font also changes in the swiftbutton, not done in code. Image 2 is as the layout designer shows.
 

Attachments

  • IMG_1.jpg
    IMG_1.jpg
    455.5 KB · Views: 218
  • IMG_2.jpg
    IMG_2.jpg
    494.2 KB · Views: 234
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The anchors in the layout are all set for horizontal-left and Vertical-top.
This is the mistake.
The views at the bottom should be anchored to the bottom.

Start with the visual designer video tutorial: https://www.b4x.com/etp.html
Also check the "handle resize event" and delete the code in the Resize event.
 
Upvote 0
Top