iOS Question Scroll view width is not correct

Sanxion

Active Member
Licensed User
Longtime User
Hi all

I am attempting to load a text file into a label and then add it to a scrollview. It is all working except that the width of the scrollview is too narrow and some of the text at the right is not being displayed. Here is the code:

B4X:
txt = File.ReadString(File.DirAssets, "Lesson0Notes.txt")    ' load the text file into the string
    lblLesson0Notes.Initialize(" ")
    lblLesson0Notes.Font = Font.CreateNew2("schalk",20)
    lblLesson0Notes.TextColor = Colors.White
    lblLesson0Notes.Multiline = True
    lblLesson0Notes.SizeToFit
    scvLesson0Notes.Panel.AddView(lblLesson0Notes,0,0,80%x,60%y)
    lblLesson0Notes.Text = txt
    scvLesson0Notes.ContentHeight = lblLesson0Notes.Height                        
    scvLesson0Notes.ScrollOffsetY = 0  
    scvLesson0Notes.Width=Page1.RootPanel.Width
    scvLesson0Notes.ContentWidth = Page1.RootPanel.Width
    lblLesson0Notes.Width=scvLesson0Notes.Width
    lblLesson0Notes.SizeToFit
    scvLesson0Notes.ContentHeight = lblLesson0Notes.Height
    scvLesson0Notes.ContentWidth = scvLesson0Notes.Width

I have adapted this from an example I saw using a text view so if it is not correct, please advise.

Thanks
 
Last edited:

tufanv

Expert
Licensed User
Longtime User
what is scv ? and what is scvlessonnotes ? do you have 2 scrollviews ? Why 2 ?
Hi all

I am attempting to load a text file into a label and then add it to a scrollview. It is all working except that the width of the scrollview is too narrow and some of the text at the right is not being displayed. Here is the code:

B4X:
txt = File.ReadString(File.DirAssets, "Lesson0Notes.txt")    ' load the text file into the string
    lblLesson0Notes.Initialize(" ")
    lblLesson0Notes.Font = Font.CreateNew2("schalk",20)
    lblLesson0Notes.TextColor = Colors.White
    lblLesson0Notes.Multiline = True
    lblLesson0Notes.SizeToFit
    scvLesson0Notes.Panel.AddView(lblLesson0Notes,0,0,80%x,60%y)
    lblLesson0Notes.Text = txt
    scvLesson0Notes.ContentHeight = lblLesson0Notes.Height                        
    scvLesson0Notes.ScrollOffsetY = 0  
    scvLesson0Notes.Width=Page1.RootPanel.Width
    scvLesson0Notes.ContentWidth = Page1.RootPanel.Width
    lblLesson0Notes.Width=scvLesson0Notes.Width
    lblLesson0Notes.SizeToFit
    scvLesson0Notes.ContentHeight = lblLesson0Notes.Height
    scv.ContentWidth = scv.Width

I have adapted this from an example I saw using a text view so if it is not correct, please advise.

Thanks
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Where is the left,height of scv ? try to make the background color of scv red and see its boundries to check if you could successfuly position the scv. That is something to do with the scrollviews position i think.
No, that was a cut and paste mistake. There is only 1.
I have corrected it now.
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
Where is the left,height of scv ? try to make the background color of scv red and see its boundries to check if you could successfuly position the scv. That is something to do with the scrollviews position i think.
I changed:
scvLesson0Notes.Width=Page1.RootPanel.Width to
scvLesson0Notes.Width=80%x (which is the width of the parent panel of the scrollview)

...and that seems to have worked.

Thank-you.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You need to define what width exactly you want !

In your code you set:
scvLesson0Notes.Width=Page1.RootPanel.Width
scvLesson0Notes.ContentWidth = Page1.RootPanel.Width

Where do you set this, in Page1_Resize ?
In this case Page1.RootPanel.Width is equal to 100%x.

Then is post#5 you set it to
scvLesson0Notes.Width=80%x
why ?

Because you set the width of lblLesson0Notes to 80%x in :
scvLesson0Notes.Panel.AddView(lblLesson0Notes,0,0,80%x,60%y)
why only 80%x ? It's less than the width of scvLesson0Notes !

You should define the width and height of scvLesson0Notes, which is the visible part on the screen.
Then you can define the internal dimensions of the ScrollView with:
scvLesson0Notes.Panel.Width and
scvLesson0Notes.Panel.Height
which is the scrolling area.
If you want only vertical scrolling you should set
scvLesson0Notes.ContentWidth = scvLesson0Notes.Width

Then when you add lblLesson0Notes onto scvLesson0Notes.Panel you must set its width the same as lblLesson0Notes, or the inverse !

And then you must adapt
scvLesson0Notes.ContentHeight = lblLesson0Notes.Height
as you did.
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
You need to define what width exactly you want !

In your code you set:
scvLesson0Notes.Width=Page1.RootPanel.Width
scvLesson0Notes.ContentWidth = Page1.RootPanel.Width

Where do you set this, in Page1_Resize ?
In this case Page1.RootPanel.Width is equal to 100%x.

Then is post#5 you set it to
scvLesson0Notes.Width=80%x
why ?

Because you set the width of lblLesson0Notes to 80%x in :
scvLesson0Notes.Panel.AddView(lblLesson0Notes,0,0,80%x,60%y)
why only 80%x ? It's less than the width of scvLesson0Notes !

You should define the width and height of scvLesson0Notes, which is the visible part on the screen.
Then you can define the internal dimensions of the ScrollView with:
scvLesson0Notes.Panel.Width and
scvLesson0Notes.Panel.Height
which is the scrolling area.
If you want only vertical scrolling you should set
scvLesson0Notes.ContentWidth = scvLesson0Notes.Width

Then when you add lblLesson0Notes onto scvLesson0Notes.Panel you must set its width the same as lblLesson0Notes, or the inverse !

And then you must adapt
scvLesson0Notes.ContentHeight = lblLesson0Notes.Height
as you did.
Thank-you for that thorough explanation Klaus.

As I mentioned in my first post, I was following an example I had seen previously and I realised that my mistake was setting the .ContentWidth to the .RootPanel.Width.
 
Upvote 0
Top