Scrolling in 2D? (ScrollView + HorizontalScrollView)

boten

Active Member
Licensed User
Longtime User
How can one go about placing a HorizontalScrollView on the inner panel of a ScrollView?

The idea is to be able to display long and wide text (like in the longtext example) without having the lines broken at the screen edge.

I first tried applying the "longtextsimple" to horizontal, replacing ScrollView with HorizontalScrollView and width/height where applicable. That was fine (except that only the first lines showed, which is natural since there's no vertical scroll).

I then tried to wrap the HorizontalScrollView "inside" a ScrollView (on it's inner panel), adjusting widths and heights according to the text (considering typeface and textsize) width & height.

It turned out that only the "first" lines (those that fit on the screen) are shown. When scrolling vertically it showed the vertical scroll panel with only the background.
 

boten

Active Member
Licensed User
Longtime User
:BangHead: :( :BangHead: :(:BangHead:

I was hoping to overcome WebView's inability to obey <pre> monospace with this double-scroll, and you suggest overcoming double-scroll with WebView.

I think I have a loop here :)

Well, my users will have to settle for proportional font in webview :confused:
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Try the attached sample program.
It uses a label wider and higher than the screen with static horizontal and vertical scrolling.
The label width is defined by the longest text line.

Best regards.
 

Attachments

  • LongWideTextDisplay.zip
    6.8 KB · Views: 1,107
Upvote 0

boten

Active Member
Licensed User
Longtime User
Thx klaus. Somehow I had the feeling that if is a scroll problem, Klaus will find a way to solve it.
You're just what the doctor ordered. :sign0060:
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
Android doesn't support any combination of scrolling views. You will need to use WebView if you need to scroll both directions.

Hello,
I needed both horizontal and vertical scrolling for an application. I saw this post and thought "oh no!". I gave it a try. It seems to be working correctly. Am I going to run into a problem later? Does the post refer to an older version?

Here is the code I am using:

B4X:
  Dim sv As ScrollView
  Dim hsv As HorizontalScrollView
  
  sv.Initialize(pnlGm.Height)
  pnlGm.AddView(sv, 0, 0, pnlGm.Width, pnlGm.Height)
  sv.Color = Colors.RGB(240,240,240)
  sv.Panel.Color = Colors.RGB(240,240,240)
  sv.Panel.Width = sv.Width
  sv.Panel.Height = l   ' l is the calculated height I need
  
  hsv.Initialize(pnlGm.Height, "hsv")
  sv.Panel.AddView(hsv, 0, 0, sv.Width, sv.Panel.Height)
  hsv.Color = Colors.RGB(240,240,240)
  hsv.Panel.Color = Colors.RGB(240,240,240)
  hsv.Panel.Height = hsv.Height
  hsv.Panel.Width = l   ' l is also the calculated with I need

  k = 0
  
  For i=0 To r-1
    For j=0 To c-1
      Dim ptile As Panel
      Dim cd As ColorDrawable
     
      ptile.Initialize("ptile")
      cd.Initialize(Colors.RGB(180,180,180), 5)
      ptile.Background = cd
      ptile.Tag = k
     
      tl = j * tsize + (j + 1) * tspc
      tt = i * tsize + (i + 1) * tspc
     
      tlist.Add(ptile)
      hsv.Panel.AddView(ptile, tl, tt, tsize, tsize)
      k = k + 1
    Next
  Next

Barry.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Do google not do this very same thing on the market. Horizontal scrolling screenshots in the vertical scrolling description of an app?
 
Upvote 0
Top