Android Question How to align things within a TabPage?

FERNANDO SILVEIRA

Active Member
Licensed User
I had a single layout named "Play" with 4 buttons that I dinamically positioned the fields within it and it seemed visually perfect. Then I decided to use TabHosts and add an extra "About" layout.

Now the original buttons that used to be aligned based on activity.Width seems a little displaced to the right of the screen. Also, a button that used to be anchored to the botton, now is hidden.

What should I consider in terms of screen size when using TabHost?

Regards,
Fernando

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Main")
    tbnPages.AddTab("Play","Play")
    tbnPages.AddTab("About","About")
    tbnPages.Height = Activity.Height
    tbnPages.Width = Activity.Width
      
    Dim wGap As Int = (tbnPages.Width - (2 * lblYellow.Width)) / 3
    lblYellow.left = wGap
    lblYellow.Top = wGap
    lblGreen.left = lblYellow.Width + (2 * wGap)
    lblGreen.Top = lblYellow.top
    lblRed.left = lblYellow.Left
    lblRed.Top = lblYellow.height + (2 * wGap)
    lblBlue.left = lblGreen.left
    lblBlue.Top = lblRed.top
End Sub
 

Eme Fibonacci

Well-Known Member
Licensed User
You can export a sample project as zip. This helps understand the issue and find a solution.
File>Export as Zip
 

klaus

Expert
Licensed User
You should use DesignerScripts in the Designer as suggested by Erel in the other thread.
Instead of adjusting the views in the code, add code below in the DesignerScripts of the Play layout.
B4X:
wGap = (100%x - (2 * lblYellow.Width)) / 3
lblYellow.left = wGap
lblYellow.Top = wGap
lblGreen.left = lblYellow.Width + (2 * wGap)
lblGreen.Top = lblYellow.top
lblRed.left = lblYellow.Left
lblRed.Top = lblYellow.height + (2 * wGap)
lblBlue.left = lblGreen.left
lblBlue.Top = lblRed.top
When you load a layout onto a Panel, 100%x is equal to Panel.Width and 100%y is equal to Panel.Height, and the anchors work !
 
Last edited:
Top