Android Question ScrollTo() in BBCodeView?

doncx

Active Member
Licensed User
Longtime User
I am switching my WebViews to BBCodeViews for better cross-platform compaitbility. Despite some searching in this forum, I have not figured out how to scroll to a particular vertical location in the view.

This requires two things: 1) a way to locate an item in the view to know it's vertical position, and 2) a means to scroll to it, ideally animated and not instant.

Is there a way to do this?

Thanks
 

William Lancee

Well-Known Member
Licensed User
Longtime User
The problem is not so much as how to scroll. You can do it with BBCodeview1.sv.ScrollViewOffsetY = position
But how do you find that position.

Let's say you want to go to the first occurrence of a word - "magic"

1. use a temporary mockup BBCodeViewX to find the height of the rendered substring of the text to the first occurrence of "magic"

Dim h As Float = BBCodeviewX.Paragraph.Height / TexttEngine1.mScale + BBCodeviewX.Padding.Top + BBCodeviewX.Padding.Bottom

2. use BBCodeview1.sv.ScrollViewOffsetY = h

Untested, but I think it will work.

(Animated, I don't know how)
 
Upvote 0

doncx

Active Member
Licensed User
Longtime User
Thanks William.

Step 2 I get. I'm having trouble seeing how step 1 finds "magic". Can you help me further with that?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Let's say you want to scroll to a phrase "all good men"

B4X:
Dim searchStr As String = "all good men"
Dim k As Int = bbcvtext.IndexOf(searchStr)
Dim stringToPhrase As String =  bbcvtext.substring2(0, k + searchStr.length)

BBCodeViewX.text = stringToPhrase                                   'a temporary BBCodeView
'get height of contents of BBCodeViewX
'scroll the full string  BBCOdeView1 to the height found above
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…