Sub Globals
Private pnlMain As Panel
Private AdMob As Boolean : AdMob = False
Private Rows As Int : Rows = 5
Private Cols As Int : Cols = 7
Private btn(Rows, Cols) As Button
Private lblTitle As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
InitCollection
SetupDesign
End Sub
Private Sub InitCollection
Private i,j As Int
For i = 0 To Rows - 1
For j = 0 To Cols - 1
btn(i,j).Initialize("btnCollection")
btn(i,j).Tag = i & "," & j
btn(i,j).Text = i & "," & j
Next
Next
End Sub
Private Sub SetupLayout
Private TrueSquare As Int
Private TitleGapY, Gap As Int
Private ScreenX, ScreenY As Int
Private GapDirectionX As Boolean
Private i,j,i1,j1 As Int : i = 0 : j = 0
Private TempRows, TempCols As Int : TempRows = Rows : TempCols = Cols
' Init pnlMain and Init lblTitle
' Don't Init btn array because that should be done at startup
pnlMain.Initialize("Activity")
lblTitle.Initialize("pnlMain")
' Make the panel depending on admob
If AdMob = True Then
Activity.AddView(pnlMain,0,50dip,100%x,100%y-50dip)
pnlMain.SetLayout(0,50dip,100%x,100%y-50dip)
Else
Activity.AddView(pnlMain,0,0,100%x,100%y)
pnlMain.SetLayout(0,0,100%x,100%y)
End If
' ScreenX & ScreenY is for calucalting the full
' Screen Real Estate
ScreenX = pnlMain.Width
ScreenY = pnlMain.Height
' Determines which way the Rows and Cols should be on the screen
' depends on orientation and Rows/Cols
If ScreenX > ScreenY AND Cols < Rows Then
TempRows = Cols
TempCols = Rows
Else If ScreenX < ScreenY AND Cols > Rows Then
TempRows = Cols
TempCols = Rows
End If
' Figure out what a TrueSquare is on the screen
' Uses the pnlMain.Width & Height instead of
' Activity.Width & Height
If (ScreenX/TempRows) > (ScreenY/TempCols) Then
TrueSquare = (ScreenY/TempRows)
Gap = ((ScreenX/TempCols) - TrueSquare)/2
GapDirectionX = True
Else
TrueSquare = (ScreenX/TempCols)
Gap = ((ScreenY/TempRows) - TrueSquare)/2
GapDirectionX = False
End If
' Make the Title, Subtract the title from the
' screen real estate, Make a Gap
pnlMain.AddView(lblTitle,0,0,100%x,TrueSquare)
TitleGapY = lblTitle.Height
ScreenY = ScreenY - TitleGapY
For i1 = 0 To TempRows - 1
For j1 = 0 To TempCols - 1
If GapDirectionX = False Then
pnlMain.AddView(btn(i,j),j1 * (ScreenX/TempCols),(i1 *(ScreenY/TempRows))+Gap+TitleGapY,ScreenX/TempCols,TrueSquare)
Else
pnlMain.AddView(btn(i,j),(j1 * (ScreenX/TempCols))+Gap,(i1 * (ScreenY/TempRows))+TitleGapY,TrueSquare,ScreenY/TempRows)
End If
i = i + 1
If i > (Rows - 1) Then
i = 0
j = j + 1
End If
Next
Next
End Sub