Android Question [SOLVED] Struggling With Anchors

mmieher

Active Member
Licensed User
Longtime User
I have been using B4A since 2012 but still struggle with multiple screen sizes. Have watched the tutorial twenty times.

Attached is a simple project. See Trigger_Page1 layout. It works if I set TOP and LEFT as anchors. If I set both HORIZONTAL and VERTICAL anchors, then the button does not show on the screen. Device is Samsung Galaxy S7.

It works with horizontal and vertical anchors if Trigger_Page1 is loaded in Activity_Create. Does not work if I call a sub. AppCompat stuff is in the Project because I use it in the App I am trying to make work.

Any ideas?
 

Attachments

  • Test.zip
    10.5 KB · Views: 195

klaus

Expert
Licensed User
Longtime User
Move the LoadLayout line after adding the Panel.

B4X:
Private Sub PageTest
    
    ''    This DOES NOT Work if Horizontal and Vertical Anchors Set
    
    Page1.Initialize("Page1")
'    Page1.LoadLayout("Trigger_Page1")
    
    Activity.AddView(Page1,0,0,100%x,100%y)
    Page1.LoadLayout("Trigger_Page1")
    
End Sub
 
Upvote 1

mmieher

Active Member
Licensed User
Longtime User
Wow. Thanks, Klaus!

Doesn't make intuitive sense, but it worked. I have written dozens of production apps and never had this problem.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Doesn't make intuitive sense
If you migrate to B4XPages, you will see that it becomes intuitive and makes a lot more sense. But if you are adding a panel programmatically, you always have to initialize it, then add it to the root or activity, then load the layout onto it in that sequence.
 
Upvote 0
Top