Resizing The Layout

P373R

Member
Licensed User
Longtime User
There is a simple way to resize a layout just by creating 1 resolution template.

Lets say we create a custom 480x480 template (This will fit for portrait and landscape formats)

Now we use some code to resize each element.
B4X:
Sub resizeLB(l As Label,stdRes as int)
   Dim LV As LayoutValues
   LV=GetDeviceLayoutValues
   Dim s As Float
   Dim m As Int
   If LV.Height < LV.Width Then
      s = LV.Height
   Else
      s=LV.Width
   End If
   m=LV.Width/2
   s = s/stdRes
   l.Width=l.Width*s
   l.Height=l.Height*s
   l.Left = (m-(stdRes/2)*s)+l.Left*s
   l.Top = l.Top*s
End Sub

Now we have a function that can resize and place the elements of type Label in the middle of the screen.
To use this function on other types just change the type of the value which is passed as Object to the function. Eg Sub resizePB(l As ProgressBar,stdRes as int) for progress bar.

Now we can launch those functions on Activity_resume since this event will be triggered each time the screen rotation is changed.
B4X:
Sub Activity_Resume
   resizePB(ProgressBar1,480)
   resizeLB(Label1,480)
   resizeLB(LabelBro,480)
End Sub
Now your layout is centered and resized to the smallest side of the screen
 
Last edited:
Top