iOS Question scrollview height

Discussion in 'iOS Questions' started by Albi, May 7, 2015.

  1. Albi

    Albi Active Member Licensed 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.

    Code:
    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: May 8, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Albi

    Albi Active Member Licensed 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
    Code:
    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)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice