Anything other than absolute layouts?

trinode

Member
Licensed User
Longtime User
I'm coming from other development environments including android within eclipse.

I'm used to things like fill_parent, the various layout managers and such to make layouts that adapt dynamically and don't necessitate multiple screen designs, even if the aspect ratio of the display is completely different.

eg: I might have 4 buttons along the top that are 25% of the width, they are a fixed height (not quite true, but simply for this example), and the rest of the screen is filled with a listview (set to fill the remaining space).

Could I simply achieve this with B4A?

- Anthony
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use %x and %y in your code to set the buttons:
B4X:
Sub Globals
   Dim b1, b2, b3, b4 As Button
   Dim ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1") 'assuming that the views are created with the designer
   b1.SetLayout(0, 0, 25%x, 50dip)
   b2.SetLayout(25%x, 0, 25%x, 50dip)
   b3.SetLayout(50%x, 0, 25%x, 50dip)
   b4.SetLayout(75%x, 0, 25%x, 50dip)
   ListView1.SetLayout(0, 50dip, 100%x, 100%y - 50dip)
End Sub
 
Upvote 0
Top