Android Question How to use scrolling on B4XMainPage

gacar

Active Member
I couldn't use scrolling on B4XMainPage. My code below

B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"

#End Region

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private ScrollView1 As ScrollView 
    Private Panel1 As Panel
End Sub

Public Sub Initialize

End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage") '>>>>>>>>>>>> If i delete here application don't run. 
    ScrollView1.Initialize(1420dip)
    Panel1.AddView(ScrollView1,0,0,100%x,100%y)
    ScrollView1.Panel.LoadLayout("MainPage") '>>>>>>>>>>>> and here duplicate
End Sub

Private Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
End Sub

resim_2022-03-29_232702.png


If use scrolling it looks like this

resim_2022-03-29_232747.png


resim_2022-03-29_232438.png
 
Solution
Your error comes from loading the same layout twice.
I usually do something along the following lines.

B4X:
Dim SV As ScrollView
SV.Initialize(Root.Height)
ScrollView.SetLayout(0, 0, Root.Width, Root.Height)
SV.Panel.LoadLayout("x")
SV.Panel.Height = LastElement.Top + LastElement.Bottom + Margin

Root.AddView(SV, 0, 0, Root.Width, Root.Height)

klaus

Expert
Licensed User
Longtime User
You should add your ScrollView in one layout file.
Load this one to Root.LoadLayout("MainPage").
And then load the other layout to ScrollView1.Panel.LoadLayout("Layout").
Do not forget to set the correct height of ScrollView1.Panel.

It would be easier for us to help if you posted your project as a zip file.
You can zip the project with this line in the IDE:
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=\%PROJECT_NAME%.zip
 
Upvote 0

gacar

Active Member
You should add your ScrollView in one layout file.
Load this one to Root.LoadLayout("MainPage").
And then load the other layout to ScrollView1.Panel.LoadLayout("Layout").
Do not forget to set the correct height of ScrollView1.Panel.

It would be easier for us to help if you posted your project as a zip file.
You can zip the project with this line in the IDE:
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=\%PROJECT_NAME%.zip
Thank you for reply. Should i move all items of mainpage to new Layout? Or can i use activity of MainPage instead of new Layout?
 
Upvote 0

gacar

Active Member
It would be easier for us to help if you posted your project as a zip file.
You can zip the project with this line in the IDE:
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=\%PROJECT_NAME%.zip

Thank you. Actually it would be good for me, because this is my first project and i am not sure is it perfect or not. But i have db password in my project then i cant share it in here. But if you want i can send an email my project.
 
Upvote 0

Spavlyuk

Active Member
Licensed User
Your error comes from loading the same layout twice.
I usually do something along the following lines.

B4X:
Dim SV As ScrollView
SV.Initialize(Root.Height)
ScrollView.SetLayout(0, 0, Root.Width, Root.Height)
SV.Panel.LoadLayout("x")
SV.Panel.Height = LastElement.Top + LastElement.Bottom + Margin

Root.AddView(SV, 0, 0, Root.Width, Root.Height)
 
Upvote 0
Solution

klaus

Expert
Licensed User
Longtime User
Should i move all items of mainpage to new Layout? Or can i use activity of MainPage instead of new Layout?
You can define a new layout with the ScrollView and load this one onto Root.LoadLayout("NewLayout").
And load MainPage onto the ScrollView.Panlel: ScrollView1.Panel.LoadLayout("MainPage").
 
Upvote 0

gacar

Active Member
Your error comes from loading the same layout twice.
I usually do something along the following lines.

B4X:
Dim SV As ScrollView
SV.Initialize(Root.Height)
ScrollView.SetLayout(0, 0, Root.Width, Root.Height)
SV.Panel.LoadLayout("x")
SV.Panel.Height = LastElement.Top + LastElement.Bottom + Margin

Root.AddView(SV, 0, 0, Root.Width, Root.Height)

Thank you. This way worked well.
 
Upvote 0
Top