A solution to multiple screen sizes.
We have solved this problem by using just one layout, then calling the following code to adjust it automatically to each screen size. SetThisLayout recursively crawls all the panels and views, and adjusting each view to the correct size and location for the screen resolution. If you support Portrait and landscape you might need two layouts per activity but never more.
Note the you need one Try-Catch block for each type of view in your layout, so you may finds some missing. Note that this also adjusts text sizes as well.
This saves us countless fiddly hours on each app.
Sub Process_Globals
'These global variables will be declared once when the application starts.
Dim DeviceLV As LayoutValues: DeviceLV = GetDeviceLayoutValues
Dim ScreenHeight As Int: ScreenHeight = DeviceLV.Height
Dim ScreenWidth As Int: ScreenWidth = DeviceLV.Width
Dim Scale As Double: Scale=DeviceLV.Scale
End Sub
Sub SetThisLayout
Dim i As Int
Dim Xscale As Double,Yscale As Double
Xscale =(screenwidth/1024)/scale
Yscale = (screenheight/600)/scale
For i = 0 To activity.NumberOfViews-1
Try
Dim PV As Panel
PV = activity.getView(i)
Dim L As Double,T As Double,W As Double,H As Double
L=PV.left*Xscale:T=PV.top*Yscale:W=PV.width*Xscale:H=PV.height*Yscale
PV.SetLayout(L,T,W,H)
SetLayoutPanel(PV,Xscale,Yscale)
Catch
End Try
Next
End Sub
Sub SetLayoutPanel(P As Panel, Xscale As Double,Yscale As Double)
Dim i As Int
Dim NoGood As Boolean: NoGood=False
For i=0 To P.NumberOfViews
Try
Dim PV As Panel
PV = P.getView(i)
Dim L As Double,T As Double,W As Double,H As Double
L=PV.left*Xscale:T=PV.top*Yscale:W=PV.width*Xscale:H=PV.height*Yscale
PV.SetLayout(L,T,W,H)
SetLayoutPanel(PV,Xscale,Yscale)
NoGood=False
Catch
NoGood=True
End Try
Try
If Nogood Then
Dim LV As Label
LV = P.getView(i)
LV.TextSize=LV.TextSize*Yscale
Dim L As Double,T As Double,W As Double,H As Double
L=LV.left*Xscale:T=LV.top*Yscale:W=LV.width*Xscale:H=LV.height*Yscale
LV.SetLayout(L,T,W,H)
NoGood=False
End If
Catch
NoGood=True
End Try
Try
If Nogood Then
Dim BV As Button
BV = P.getView(i)
BV.TextSize=BV.TextSize*Yscale
Dim L As Double,T As Double,W As Double,H As Double
L=BV.left*Xscale:T=BV.top*Yscale:W=BV.width*Xscale:H=BV.height*Yscale
BV.SetLayout(L,T,W,H)
NoGood=False
End If
Catch
NoGood=True
End Try
Try
If Nogood Then
Dim IV As ImageView
IV = P.getView(i)
Dim L As Double,T As Double,W As Double,H As Double
L=IV.left*Xscale:T=IV.top*Yscale:W=IV.width*Xscale:H=IV.height*Yscale
IV.SetLayout(L,T,W,H)
NoGood=False
End If
Catch
NoGood=True
End Try
Try
If Nogood Then
Dim HV As HorizontalScrollView
HV = P.getView(i)
HV.Panel.Width=HV.Panel.Width*Xscale
Dim L As Double,T As Double,W As Double,H As Double
L=HV.left*Xscale:T=HV.top*Yscale:W=HV.width*Xscale:H=HV.height*Yscale
HV.SetLayout(L,T,W,H)
NoGood=False
End If
Catch
NoGood=True
End Try
Try
If Nogood Then
Dim SB As SeekBar
SB = P.getView(i)
Dim L As Double,T As Double,W As Double,H As Double
L=SB.left*Xscale:T=SB.top*Yscale:W=SB.width*Xscale:H=SB.height*Yscale
SB.SetLayout(L,T,W,H)
NoGood=False
End If
Catch
NoGood=True
End Try
Next
End Sub