Android Question ScrollView not scrolling

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to Everybody
I have a strange situation, using a ScrollView. The following code worked in the past. Now I am trying to re-use it and the scrollview that I used, doesn't scroll automatically. The ScrollView is named "Lista" and is defined in the designer (with internal height 500, the default). The sub assumes a global iRow counter that is sequentially incremented by other operations.

B4X:
Sub AddLineToList
    
    Dim Row As Panel
    Dim pos As Int
    Dim RowHeight,nRowPage As Int
   
    RowHeight=26dip

    nRowPage=Lista.Height/RowHeight

    Row.Initialize("")
    '.....
    ' Row is filled by other Views that I omit to avoid confusion
    ' then Row is added to the Lista.Panel at iRow-1 position

    Lista.Panel.AddView(Row,1,2dip+(iRow-1)*(RowHeight) ,Lista.Width-6,RowHeight)
    
    pos=RowHeight*(iRow-nRowPage+1)

    If pos>0 Then
        Lista.ScrollPosition=pos ' doesn't work ... nothing happens .
    End If
End Sub
In my case, I have 23 nRow. Initially pos is negative, but also when it becomes positive (adding rows, incrementing iRow), the ScrollView doesn't scroll up...BUT, as I said, such code worked in other Apps and I don't figure out what is now happening or what I am missing..
Thanks in advance for any hint.
 
Solution
The attached project works as you expect it to work with both anchor types.
The problem in your code with my solution is that you changed a few things:
- the value of iLettura begins with 1 but iRow begins with 0.
- nRowPage = ScrollView1.Height/RowHeight in my code becomes
nLPagMisure=Lista.Panel.Height/LineHeight in your code, why ?
I use the Scrollview.Height but you use the Scrollview.Panel.Height
You did not take this in account.

I added this line
Lista.Panel.Height = Lista.Height
to avoid problems depending on the Lista.Height you define in the Designer and the value of the internal panel height in the Designer.
Top