iOS Question scrollview height

Albi

Active Member
Licensed User
Longtime User
Hello,

Using bits from B4A and other B4i questions I did a scrollview, and placed within it a textview.
However, the scrolling isn't great, it sometimes bounces back to the start, and sometimes goes to the end. I've had something like this before, and from the logs it seems to not be aligned between the contentheight and the height of the text that's there.

the code i used is essentially this, in application start. the "longtext" file just has a textview (txvScroll) which takes up the entire layout.

B4X:
    scrHelp.Panel.LoadLayout("longtext")
    txvScroll.Text = "Welcome to help." & CRLF & _
                "There will be lots of text here." & CRLF & _
....lots more lines....

    adjustHeight
    adjustHeight
    adjustHeight
end sub

Sub adjustHeight
    Log ("tsv scroll height: " & txvScroll.Height)
    txvScroll.SizeToFit
    Log ("tsv scroll height: " & txvScroll.Height)
    scrHelp.ContentHeight = txvScroll.Height
    scrHelp.ContentWidth = scrHelp.Width
    txvScroll.Width = scrHelp.Width
End Sub

i found previously, that calling the adjust height function a few times got the (re?)sizing to behave perfectly. in this case however, it doesn't.
the logs output something like this:

tsv scroll height: 500
tsv scroll height: 1542.5
tsv scroll height: 1542.5
tsv scroll height: 518.5
tsv scroll height: 518.5
tsv scroll height: 518.5

i've attached the project too in case any one wants to see that too.
 
Last edited:

Albi

Active Member
Licensed User
Longtime User
thanks, that works well for me.

i dreamt about this and woke up with the realisation that what i should have had above was
B4X:
Sub adjustHeight
  scrHelp.ContentWidth = scrHelp.Width
  txvScroll.Width = scrHelp.Width
  txvScroll.SizeToFit
  scrHelp.ContentHeight = txvScroll.Height
End Sub

and then i only need to call it once (though it still outputs the wrong height in this case, but not in another app that i am making)
 
Upvote 0
Top