Try to make an app scalable horizontally and scrollable vertically.

mattdavis523

Member
Licensed User
Longtime User
Hi I'm coming from app inventor and have created an app for tracking volleyball stats. The app contains rows and columns of buttons. In app inventor there is a function called fill parent that will stretch views to equally fill the parent object in my case the screen and when the app takes up more room vertically it is automatically scrollable. I'm trying to create this app again using B4A, but can't figure out how to make the app scrollable. I have attached a dropbox link since the app is too big to post here, a drawback of app inventor. Any help would be much appreciated.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I was only able to run your app in the third time. It is extremely slow and unresponsive on the device I ran it.

The following code creates a similar interface (project is attached):
B4X:
Sub Process_Globals
   Type Player(Name As String, Values() As Int)
   Type PlayerColumn (Player As Player, Column As Int)
   Dim Players As List
   Dim NUM_COLUMNS As Int : NUM_COLUMNS = 6
   Dim ROW_HEIGHT As Int : ROW_HEIGHT = 60dip
   Dim PLAYER_NAME_WIDTH As Int : PLAYER_NAME_WIDTH = 100dip
End Sub

Sub Globals
   Dim TopPanel As Panel
   Dim BottomPanel As Panel
   Dim ScrollView1 As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      Players.Initialize
      For i = 0 To 29
         Dim p As Player
         p.Name = "Player " & (i + 1)
         Dim values(NUM_COLUMNS) As Int
         p.Values = values
         Players.Add(p)
      Next
   End If
   Activity.LoadLayout("1")
   TopPanel.Width = 100%x
   BottomPanel.Width = 100%x
   BottomPanel.Top = 100%y - BottomPanel.Height
   ScrollView1.Height = BottomPanel.Top - ScrollView1.Top
   ScrollView1.Width = 100%x
   CreateListOfPlayers(30)
End Sub

Sub CreateListOfPlayers(Count As Int)
   
   ScrollView1.Panel.Height = Count * ROW_HEIGHT
   Dim btnWidth As Int
   btnWidth = (ScrollView1.Width - PLAYER_NAME_WIDTH) / NUM_COLUMNS
   
   For i = 0 To Count - 1
      Dim p As Player
      p = Players.Get(i)
      Dim et As EditText
      et.Initialize("PlayerName")
      ScrollView1.Panel.AddView(et, 0, i * ROW_HEIGHT + 5dip, PLAYER_NAME_WIDTH, ROW_HEIGHT - 10dip)
      et.Text = p.Name
      et.SingleLine = True
      et.Tag = p
      et.ForceDoneButton = True
      
      For c = 0 To NUM_COLUMNS - 1
         Dim pc As PlayerColumn
         pc.Player = p
         pc.Column = c
         Dim b As Button
         b.Initialize("Button")
         ScrollView1.Panel.AddView(b, PLAYER_NAME_WIDTH + c * btnWidth, _
            i * ROW_HEIGHT, btnWidth, ROW_HEIGHT)
         b.Tag = pc
         b.Text = p.Values(c)
      Next
   Next
End Sub

Sub PlayerName_EnterPressed
   Dim v As EditText
   v = Sender
   Dim P As Player
   P = v.Tag
   P.Name = v.Text
End Sub

Sub Button_Click
   Dim b As Button
   b = Sender
   Dim pc As PlayerColumn
   pc = b.Tag
   Dim p As Player
   p = pc.Player
   p.Values(pc.Column) = p.Values(pc.Column) + 1
   b.Text = p.Values(pc.Column)
End Sub

It only handles the ScrollView layout.
 

Attachments

  • 1.zip
    6.7 KB · Views: 239
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…