Real newb question about how to display a block of scrollable text

mistermentality

Active Member
Licensed User
Longtime User
Okay so hopefully you will excuse the newb nature of this question given that my only experience of Android programming until now has been app inventor but....

What is the simplest option to present a block of text on screen that the user can scroll through if it is larger than the display area?I have tried a text box and a label but neither let me scroll text.

I know this is going to be simple to most people but I'm learning by testing things with the trial version at the moment and I'm sure I am missing something obvious, but what?

I'm just after something with a transparent background that can scroll up or down to read a block of text so if you excuse the newb question, any help is appreciated :)

Dave
 

mistermentality

Active Member
Licensed User
Longtime User
I did set it to false but it made no difference, however I only tried this in the emulator maybe I will try later connected to my phone as I know that some things are different on an actual device than in an emulator.

Will try that again but without the emulator. Thanks :)

Dave
 
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
Was able to try one test example on phone before subsequent ones refused to install to the phone and it did scroll, so thank you :)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached you have an example of scrolling a long text in a Label in a ScrollView object.
The original program uses the Reflector library, but as you are not a registered user you have no access to it.
The attached version uses a Label with fixed height, the original version adjusts the height of the label and internal Panel to the text height using Reflector library.

Best regards.

Edit: added HelpScrollView with the reflection library.

Edit: 2011.11.19 Updated the project,
- replaced the reflection library to get the label height by StringUtils.MeasureMultilineTextHeight.
- corrected an error with pnlHelp

Edit: 2011.12.05
- simplified the display code, removed a workaround for the height update
- removed a DoEvents, not needed anymore

Edit: 2011.12.27
- amended the problem of the text going down one line when the device is paused, mentioned here.
 

Attachments

  • HelpScrollView.jpg
    HelpScrollView.jpg
    43.4 KB · Views: 34,118
  • HelpScrollView.zip
    12.5 KB · Views: 204
Last edited:
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
Attached you have an example of scrolling a long text in a Label in a ScrollView object.
The original program uses the Reflector library, but as you are not a registered user you have no access to it.
The attached version uses a Label with fixed height, the original version adjusts the height of the label and internal Panel to the text height using Reflector library.

Best regards.

Thank you. I shall be purchasing this very soon :)

Dave
 
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
Just been looking at it,thank you. I am new to the language but I think I get how it works, which it does. Thank you for the help:)

Dave
 
Upvote 0

brainfart

Member
Licensed User
Longtime User
Trouble using reflector library to get label object height

Hello.
I have based my Help panel on your example (loosely)
The trouble is that the result of running the "getHeight" method always returns 0 (Log(Height) bellow in code) and only the fixed +10dip of label text show up.
Here is my code (see any thing wrong?):

B4X:
Sub HelpScreen
    svHelp.ScrollPosition=0
    Dim Height As Float
    lblHelpHdg.Text = "User Manual / Help"
    lblHelpHdg.Gravity = Gravity.CENTER
    lblHelpHdg.TextSize = 16dip
    lblHelpHdg.TextColor = Colors.Yellow
    lblHelpHdg.Color = Colors.DarkGray
    lblHelp.Color = 0xFFFFFDB2
    svHelp.Color = 0xFFFFFDB2
    lblHelp.TextSize = 10dip
    lblHelp.TextColor = Colors.Black
    lblHelp.Height=-2
    svHelp.Invalidate
    'Fill the label with some lines of text
    Dim i As Int
    lblHelp.Text = ""
    For i = 0 To 50
        lblHelp.Text = lblHelp.Text & "This is a test" & CRLF
    Next
    'This will use reflector library to get label object height and adjust the scrollview panel height as needed.
    Reflect.Target = lblHelp
    DoEvents        ' needed to update the value
    Height=Reflect.RunMethod("getHeight")
    Log(Height)
    DoEvents        ' needed to update the value
    svHelp.Panel.Height=lblHelp.Top+Height+10dip
    DoEvents
    State = "Help"
    WhatIsUp  'Show and hide panels based on State
End Sub
:sign0085:
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
If you look carefully at the original program you are missing following lines:
B4X:
svHelp.Panel.Height=lblHelp.Top+Height+10dip
DoEvents
[COLOR=red]If scvHelp.Panel.Width=scvHelp.Width OR scvHelp.Panel.Width=-1 Then[/COLOR]
[COLOR=red] scvHelp.Panel.Width=scvHelp.Width-1[/COLOR]
[COLOR=red]Else[/COLOR]
[COLOR=red] scvHelp.Panel.Width=scvHelp.Width[/COLOR]
[COLOR=red]End If[/COLOR]
State = "Help"
WhatIsUp  'Show and hide panels based on State
End Sub

It's a workaround to garantie the height change, without these lines the height change is not effective. It seems that there is a need for a width change to also force the height change.

Best regards.
 
Upvote 0

HDBarodi

Member
Licensed User
Longtime User
Attached you have an example of scrolling a long text in a Label in a ScrollView object.
The original program uses the Reflector library, but as you are not a registered user you have no access to it.
The attached version uses a Label with fixed height, the original version adjusts the height of the label and internal Panel to the text height using Reflector library.

Best regards.
Dear,
I am so new in this program (I purchase it just today), and when I read the example I found that the most important part is:
B4X:
Height = StrUtils.MeasureMultilineTextHeight(lblHelp3, txt3)
scvHelp.Panel.Height = lblHelp3.Top + Height + 10dip
lblHelp3.Height = Height
but I am unable to know how you make the connection between the Label and the ScrollView.
When I put the previous code in my program, I found that I can scroll the ScrollView but there is no relation between the Label and the ScrollView, and the Label stay fixed.
So, would you please help me in that?
Thanks in advance
H D Barodi
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Do you have a view called lblHelp3 in your project ?
If yes, where and how did you add it ?

In the HelpScrollView example lblHelp3 is a child of the internal ScrollView.Panel !
In the ScrollView.Panel there are two labels on top and the third one just below and the height of this label is calculated with StrUtils.MeasureMultilineTextHeight(lblHelp3, txt3) to adapt the ScrollView.Panel.Height to the displayed text.

You can also have a look ar very simple example of a long text here.

Best regards.
 
Upvote 0

HDBarodi

Member
Licensed User
Longtime User
Do you have a view called lblHelp3 in your project ?
If yes, where and how did you add it ?

In the HelpScrollView example lblHelp3 is a child of the internal ScrollView.Panel !
In the ScrollView.Panel there are two labels on top and the third one just below and the height of this label is calculated with StrUtils.MeasureMultilineTextHeight(lblHelp3, txt3) to adapt the ScrollView.Panel.Height to the displayed text.

You can also have a look ar very simple example of a long text here.

Best regards.
Many many many thanks.
What I did is that I start the designer, add both tools, and then generate, and I tried to change the parent from designer but it the ScrollView is not listed there.
Again, Thank you very much.
 
Upvote 0

HDBarodi

Member
Licensed User
Longtime User
Note that you can also use CustomListView class to show scrollable text (it is based on StringUtils.MeasureMultilineTextHeight).
Thanks Erel,
I prefer now to be able to use the basic tools, and then I will go for the professional ones, but what you mentioned here is really interesting, and spark an idea in my mind.
Can we use "StringUtils.MeasureMultilineTextHeight" to calculate the height of ListView item? For example something like:
B4X:
vHeight = StrUtils.MeasureMultilineTextHeight(ListViewResults.TwoLinesLayout.Label, ListViewResults.GetItem(0))
Because how I will guarantee that the length of the item which I add will be short enough to be displayed in one line?

Best regards,
H D Barodi
 
Upvote 0
Top