In my application I need to show some instructions (nearly 200 lines). I created a new activity and added the text in an edittext-control. It works but the scrolling of the lines is not the best.
Perhaps there is a better control for showing large text-files? Any ideas?
So I quickly noticed by hardcoding a number such as -50 is a problem as it isn't perfect for every resolution.
Is there an easy way to get the true height of the label?
I've placed several message boxes throughout the code to try to grab the label height after text is loaded:
Msgbox(lblText.Height,"")
what I always get is a -2
I'm guessing from this line:
scvText.Panel.AddView(lblText, 15, 10 ,95%x, -2) ' add the Label on the ScrollView internal Panel -2 to automatically adapt the Label height to the text height
Dim p As Label
p.Initialize("")
p.Text = DocText
sv.Panel.AddView(p, 0, 0, sv.Panel.Width, sv.Panel.Height)
Dim a As StringUtils
b = a.MeasureMultilineTextHeight(p,p.Text)
p.Height = b
sv.Panel.Height = b
where
b = a.MeasureMultilineTextHeight(p,p.Text)
gives
"java.lang.IllegalArgumentException: Layout: -1 < 0"
Hi MDEnt,
Attached you find a modified version of the LongText example with a button at the bottom.
Sorry for the late answer, yesterday I was on a party and today I was hiking in the mountains.
Oh no problem - and thanks for the help. I'll take a look at the file to see... but what I discovered while tinkering around is that if I modify your line where the ht=panel height (in the set text sub - I got it to work!
Is there a property to change the color of the vertical "handle" or "bar" that appears when the text scrolls? Only see the obvious Color propoerty for the background from the list of options.
A sort of general aside for all of our expert B4a people out there...
The experience level both in outright software development and using B4a appears to range from virtually 0 on up, I think it would be very helpful if, whenever we develop something new, we also include an in depth step by step tutorial that doesn't assume prior programming knowledge. Those of us who have such knowledge can skim over the baby steps. Just a thought.
This is related to yours and Peacemaker's post. I seem to have discovered a minor problem with MeasureMultilineTextHeight. In determining the height for the label and sv.panel it seems to work well until the label.textsize is increased above 20. I initially set the textsize = 20, but decided I wanted it more readable so increased it first to 22 and then to 24 but continue to use the height determined by MeasureMultilineTextHeight. At 22 a portion of the last line was hidden and at 24, all of the last line and the bottom portion of the line above were hidden. I resolved the problem by the following lines
Dim Ht As Int
Dim SU As StringUtils
Ht = SU.MeasureMultilineTextHeight(Label1, Label1.Text) + (Label1.TextSize * 3)
sv.Panel.Height = Ht
Label1.Height = Ht
However, I don't know if this will work for larger values.
For future user I'm adding my 2 pences to this very useful tread.
You can create you scrollview (scv) and label (lbl) in designer too (so you can easily control the layout if you need more views)
You can reuse this code with few adjustment
- do not initialize scv and lbl (they already are in the layout)
- when adding the lbl to the scv, you before have to remove lable's parent
The Label shows the special characters if the original text is encoded with UTF-8 encoding which is the standard encoding in Android.
Where does your text come from ?
You might have a look at chapter 14.10.6 Text encoding in the Beginner's Guide.