iOS Question Adding B4XViews by code

mcorbeel

Active Member
Licensed User
Longtime User
I usesd this topic for adding controls by code:
Though this works fine in B4A it does not in B4i. The controls are added to the panel but they keep their position as set in the designer. Setting TOP and LEFT has no effect. Is this solvable?
 

mcorbeel

Active Member
Licensed User
Longtime User
Yes, with an example project, what shows the behaivior.
Thanks. I created as sample project and in that project it does work. In my existing project with shared code with B4A and B4i it works in B4A but not in B4i. I cannot share my existing project, so do you have any ideas of how I can troubleshoot this?
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I made a small progress. Adding the control to the root panel is okay, both B4A and B4i. But I always use a scrollview and there positioning in B4i does not work. I created a small sample project but I cannot upload it and get message that it is too large. So I just add my code here.
B4X:
Sub Class_Globals
    Private RootPanel As B4XView
    Private ScrollViewPanel As B4XView
    Private xui As XUI
    Private B4XComboBox1 As B4XComboBox
    Private Scrollview As ScrollView
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    RootPanel = Root1
End Sub


Private Sub B4XPage_Appear()
    RootPanel.RemoveAllViews
    
    #if b4a
    Scrollview.Initialize(100%x)
    #End If
    
    #if b4i
    Scrollview.Initialize("", 100%x, 100%y)
    #End If
    
    RootPanel.AddView(Scrollview, 0, 0, 100%x, 100%y)
    ScrollViewPanel = Scrollview.Panel


    'adding the layout to the scrollview panel (is what I need)
    'positioning works in B4a, NOT in B4i
    ScrollViewPanel.LoadLayout("MainPage")

    
    'adding the layout to the main panel (test only, because I do need the scrollview)
    'positioning works in B4A and B4i
    'RootPanel.LoadLayout("MainPage")

    
    B4XComboBox1.mBase.Left = 50dip
    B4XComboBox1.mBase.Top = 100dip
    
    Dim oList As List
    oList.Initialize
    oList.Add("aaa")
    oList.Add("bbb")
    oList.Add("ccc")
    B4XComboBox1.SetItems(oList)
End Sub
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
Just place a Sleep(50) after the LoadLayout, it needs a little time to initialize before you can change the position.
When I put the Sleep(50) after the LoadLayout in the sample app then indeed the issue is solved. When I do this in my live app it is NOT fixed. But in the live app there is a lot more happening, like a few http calls before the LoadLayout ...
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I have solved the issue by unchecking the checkbox "Handle Resize Event" in the properties of the form in the designer. Me happy!

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…