Android Question ScrollView don't scroll ?

FabioG

Active Member
Licensed User
Longtime User
Hello,

I have a problem

I am creating a menu for the settings of my app
I creao a scrollview and a Panel
where I add the various items.

the ScrollView does not scroll
How can I fix the problem?
Use this code

thank you very much

B4X:
Sub LoadMenu
   
    scvMain.Initialize(0)
    Panel1.Initialize("")
   
    Panel1 = scvMain.Panel
    Activity.AddView(scvMain, 0, 0, 100%x, 100%y)

    scvMain.Panel.Height = Panel1.Height
   
    Dim LblChk As Label
    LabelTitle.Initialize("")
   
    ' *** TITLE MAIN
    LabelTitle.Text = "Title1"
    LabelTitle.Gravity = Gravity.CENTER_VERTICAL
    LabelTitle.TextSize = 16
    scvMain.Panel.AddView(LabelTitle, 8%x, 5dip, LabelTitle.TextSize*Height, Height)
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, 43dip, 90%x, 3dip)   

    Position = 1
   
    Lbl_1.Gravity  = Gravity.CENTER_VERTICAL
    Lbl_1.Text = "Name"
    scvMain.Panel.AddView(Lbl_1, 10%x, Height * Position, 180dip, Height)
   
    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    Lbl_1.Gravity  = Gravity.CENTER_VERTICAL
    Lbl_1.Text = "EncType"
    scvMain.Panel.AddView(Lbl_1, 10%x, Height * Position, 180dip, Height)
   
    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    Lbl_2.Gravity  = Gravity.CENTER_VERTICAL
    Lbl_2.Text = "Password"
    scvMain.Panel.AddView(Lbl_2, 10%x, Height * Position, 180dip, Height)
   
    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    Lbl_3.Gravity  = Gravity.CENTER_VERTICAL
    Lbl_3.Text = "Chanl"
    scvMain.Panel.AddView(Lbl_3, 10%x, Height * Position, 180dip, Height)




    ' *** TITLE Device Settings
    Position = Position + 1
    LabelDeviceSetings.Initialize("")
    LabelDeviceSetings.Text = "Device Settings"
    LabelDeviceSetings.Gravity = Gravity.CENTER_VERTICAL
    LabelDeviceSetings.TextSize = 16
    scvMain.Panel.AddView(LabelDeviceSetings, 8%x, Height * Position, LabelDeviceSetings.TextSize*Height, Height)
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 3dip)   
   
    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    Lbl_Int.Gravity  = Gravity.CENTER_VERTICAL
    Lbl_Int.Text = "Int"
    scvMain.Panel.AddView(Lbl_Int, 10%x, Height * Position, 180dip, Height)

    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    Lbl_Method.Gravity  = Gravity.CENTER_VERTICAL
    Lbl_Method.Text = "Method"
    scvMain.Panel.AddView(Lbl_Method, 10%x, Height * Position, 180dip, Height)
   
    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    LblChk.Initialize("")
    LblChk.Text = "Title3"
    LblChk.Gravity = Gravity.CENTER_VERTICAL
    scvMain.Panel.AddView(Chk_NoFwRel, 80%x, Height * Position, 120dip, Height)
    scvMain.Panel.AddView(LblChk, 10%x, Height * Position, 180dip, Height)

    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    Lbl_Drivers.Gravity  = Gravity.CENTER_VERTICAL
    Lbl_Drivers.Text = "Drv"
    scvMain.Panel.AddView(Lbl_Drivers, 10%x, Height * Position, 180dip, Height)

    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    Lbl_Mode.Gravity  = Gravity.CENTER_VERTICAL
    Lbl_Mode.Text = "WiFi Mode"
    scvMain.Panel.AddView(Lbl_Mode, 10%x, Height * Position, 180dip, Height)

    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    Lbl_Type.Gravity  = Gravity.CENTER_VERTICAL
    Lbl_Type.Text = "Type"
    scvMain.Panel.AddView(Lbl_Type, 10%x, Height * Position, 180dip, Height)   
   
    ' Keep Screen ON
    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    LblChk.Initialize("")
    LblChk.Text = "Keep ON"
    LblChk.Gravity = Gravity.CENTER_VERTICAL
    scvMain.Panel.AddView(Chk_KeepON, 80%x, Height * Position, 120dip, Height)
    scvMain.Panel.AddView(LblChk, 10%x, Height * Position, 180dip, Height)   

    Position = Position + 1
   
    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)
   
    LblChk.Initialize("")
    LblChk.Text = "Stand-By"
    LblChk.Gravity = Gravity.CENTER_VERTICAL
    scvMain.Panel.AddView(Chk_StandBy, 80%x, Height * Position, 120dip, Height)
    scvMain.Panel.AddView(LblChk, 10%x, Height * Position, 180dip, Height)   
   
   
   
   

    Panel1.Height = 100%y '5 * Height
   
End Sub
 

klaus

Expert
Licensed User
Longtime User
There are several 'strange' things in your code:
- You define Panel1 beeing scvMain.Panel but you add use almost every time scvMain.Panel, why ?
- At the end you set Panel1.Height = 100%y which is also the ScrollView height so it's normal that you don't have any scrolling !
- Remove all lines containing Panel1.
- Calculate the total height of the panel and at the end set scvMain.Panel.Height = TotalHeight.
- Where do you Dim LabelTitle ?
You Dim LblChk one time but you initialize it several times !?
You must dim it each time you use it as a new instance.
What is Line and where do you dim it ?
In this part:
B4X:
    Position = Position + 1

    Col.Initialize(Colors.DarkGray, 0)
    Line.Initialize("")
    Line.Background = Col
    scvMain.Panel.AddView(Line, 5%x, Height * Position, 90%x, 1dip)

    Lbl_1.Gravity  = Gravity.CENTER_VERTICAL
    Lbl_1.Text = "EncType"
    scvMain.Panel.AddView(Lbl_1, 10%x, Height * Position, 180dip, Height)
Here you set Line and Lbl_1 at the same Top value, I'm not sure that this will liio OK, might depend on the label background.
- You use several Labels without having dimed them or where do you dim them ?

It would be easier to help you if you posted a small project, as a zip file, showing the problem.
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User

Thanks for you reply!

I can not post the project
it is a paid app
the label is declared in globals

everything works but the scroll does not work

I removed Panel1.Height = 100%y
but it still does not work scroll

any suggestions?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Like I already told you:
- Calculate the total height of the panel and at the end set scvMain.Panel.Height = TotalHeight.
It seems that not all items in the ScrollView have the same height so you need to calculate the total height of the panel.
If all items have the same hieght you could set, at the end of the routine, scvMain.Panel.Height = (Position + 1) * Height or scvMain.Panel.Height = TotalHeight if you calculate it.
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User

Working perfect
scvMain.Panel.Height = (Position + 1) * Height

Thanks very mutch Klaus!!!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…