Sub Class_Globals
Private Root As B4XView
Private xui As XUI
#if B4J
Private Pane1 As Pane
Private ScrollPane1 As ScrollPane
#End If
#if B4A
Private Panel1 As Panel
Private ScrollView1 As ScrollView
#End If
End Sub
Public Sub Initialize
B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
B4XPages.SetTitle(Me,"Buttons grid")
#if B4J
set_button_grid(99,50,50,5)
#End If
#if B4A
Dim scale As Int = GetDeviceLayoutValues.Scale
Dim tabletsize As Int = GetDeviceLayoutValues.ApproximateScreenSize
If tabletsize >= 8 Then
scale = 2
End If
set_button_grid(99,50dip*scale,50dip*scale,5dip)
Panel1.RemoveView
ScrollView1.Panel.AddView(Panel1,0dip,0dip,ScrollView1.Width,Panel1.Height)
ScrollView1.Panel.Height = Panel1.Height
#End If
End Sub
Private Sub B4XPage_Resize (Width As Int, Height As Int)
#if B4J
set_button_grid(99,50,50,5)
ScrollPane1.InnerNode = Pane1
#End If
End Sub
Private Sub set_button_grid(cnt As Int, width As Int, height As Int, gap As Int)
#if B4J
Pane1.RemoveAllNodes
#End If
#if B4A
Panel1.RemoveAllViews
#End If
Dim rowpos As Int = gap
Dim colpos As Int = gap
For i = 0 To cnt
Dim btn As Button
btn.Initialize("btn")
btn.Text = "b" & i
btn.Tag = btn.Text
#if B4J
btn.prefWidth = width
btn.PrefHeight = height
Pane1.AddNode(btn,colpos,rowpos,width,height)
#End If
#if B4A
btn.Width = width
btn.Height = height
Panel1.AddView(btn,colpos,rowpos,width,height)
#End If
colpos = colpos + width + gap
If colpos > (Root.Width - width) Then
rowpos = rowpos + height + gap
colpos = gap
End If
Next
#if B4J
Pane1.PrefHeight = rowpos + height + gap
#End If
#if B4A
Panel1.Height = rowpos + height + gap
#End If
End Sub
Private Sub btn_Click
Dim btn As Button = Sender
Log("btn " & btn.Tag & " clicked")
End Sub