Android Question [B4X] Panel width - how to remove gabs between panels

Alexander Stolte

Expert
Licensed User
Longtime User
I add 7 panels to the main panel and resize them to fit so that they are displayed side by side. This causes 2 gaps between the panels.
B4X:
    For i = 0 To 7 -1
        Dim xpnl As B4XView = xui.CreatePanel("")
        xpnl.Color = xui.Color_Red
        Panel1.AddView(xpnl,Panel1.Width/7*i,0,Panel1.Width/7,Panel1.Height)
    Next

How can i remove this 2 white gabs?
The main panel is white.
1615542767652.png
 

Attachments

  • Test.zip
    8.3 KB · Views: 204

roumei

Active Member
Licensed User
It's caused by the float to int conversion. You could try something like this:
B4X:
Panel1.AddView(xpnl,Floor(Panel1.Width/7*i),0,Ceil(Panel1.Width/7),Panel1.Height)
This will create 7 panels with a constant width and a slight overlap and makes sure that no gaps are visible. If the overlap is not acceptable, you can create 6 panels with a width of int(Panel1.Width/7) and the seventh with the remaining space Panel1.Width-6*int(Panel1.Width/7).
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Possibly just add extra dip to the width ? ..

B4X:
Panel1.AddView(xpnl,Panel1.Width/7*i, 0, (Panel1.Width/7) +1Dip, Panel1.Height)

Edit : added border to panels as a test , the result appeared Ok...
 
Last edited:
Upvote 0
Top