Bug? ScrollView

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
I derived a table from examples here in the site. The difference is that, while in the examples the parent of the scrollview used to make the table is directly the Activity, and the scrollview is defined in the Designer too, in my case I defined in the Designer a Panel, and then the ScrollView is programmatically defined as shown in the code below. The two variants of the layout have also a difference: in the 320x480 the Panel covers almost all the surface, leaving two buttons on the bottom, while in the 600x960 the Panel covers nearly half of the surface (this allows for keeping the keyboard active, in the only case of a tablet). The bad surprise is that the table scrolls well on a 320x480 smartphone while on a tablet with 600x960 resolution, it doesn't move at all. This should mean that a problem is connected with the resolution. It could be the InnerHeight property of the scrollview, but this property is not available (if I see well) if we define the scrollview in the program and not in the designer. Moreover, even putting its equivalent, namely the "Height" (see code), to high values seem to have effect. By the way, obviously, the examples taken from the site work well .. Any suggestion? Thanks in advance..
Attach the layout file AcmAcc.bal. The code defining the Table is:

' iTab is the indicator of the Table, say 0 (zero)
' Panel1 is the container, defined in the Designer
' SV(iTab) is the ScrollView
Sub Tabella(Dir As String, HeadersExist As Boolean,iTab As Int)
SV(iTab).Initialize(0)
SV(iTab).Panel.Color=Colors.Black
Table = SV(iTab).Panel
Table.Height=1000dip ' no effect ..
Table.Color = Colors.Black
Panel1.AddView(SV(iTab), 0dip, 8%y, 100%x, 70%y)
SelectedRow = -1
JavObj=SV(iTab) ' this and the following disable the ScrollBar ..no effect even commenting them out
JavObj.RunMethod("setVerticalScrollBarEnabled", Array As Object(False))
' follows the same function used in the examples for displaying a csv file table
LoadTableFromCSV(File.DirInternalCache, BuildCsvName(iTab), HeadersExist,iTab)
End Sub
 

Attachments

  • acmacc.bal
    3.3 KB · Views: 246

klaus

Expert
Licensed User
Longtime User
I'm afraid that you are mixing up things.
You need to initialize the Table and the scrollview is automatically generated inside the class.
I don't really understand what exactly you want to do.
Could you post your project as a zip file so I could have a look at it.
 

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi Klaus, thanks for your interest. This project is rather complex I cannot post it, but, moreover, it works, on some devices. I will try to make a simpler one, to show the problem, and post it. Basically I did nothing special: I just put a Panel over the surface where the scroll view is. I could think to have done a big mistake, because (perhaps) the actions done one the surface could be catched by the panel and not by the scrollview, but things work on a smartphone. So the problem is connected to something happening in the tablet.. Anyway, as I said, I will try to reproduce the problem in a simpler environment. Thanks for now.
 

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
By the way I have discovered the reason of this misterious behavior, not a bug in the common sense. I write here the explanation, just for the benefit of another guy that may naively do what I did.
As written in my post, the Table is not inserted directly with the Designer in activity, as a ScrollView. Instead, a Panel (Panel1) is inserted, just like a "placeholder". Then, in the program, after loading the Layout with the Panel, I create the ScrollView (SvItab) and insert it in the panel with:

Panel1.AddView(SViTab, 0dip, 10%y, 100%x, 70%y)

The mistake is in the % of the y. As a matter of fact, in the above code, you will not see the 10% upper and the 30% lower part of the ScrollView.
This can be not noticed if the ScrollView is much longer of the placeholder. But if its height is such that the ScrollView is completely contained in placeholder, despite you will not see all of it, the scroll will not happen (and you never will see the missing parts, at least the bottom one, for the top I didn't pay attention, to be sincere).
This, at least, seems to me the explanation of what happened in my case. Adding the ScrollView with:

Panel1.AddView(SViTab, 0dip, 0%y, 100%x, 100%y)

Resolves my issue.
 

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi Klaus, sorry, I was thinking closed the topic and didn't look at your reply. I don't put any table onto a ScrollView. Probably I didn't explain well. Forgive my english. Erel already pointed out elsewhere that my posts are not clear (despite my efforts). The misunderstanding may arise from the fact that (for me) the "Table" is the ScrollView, meanwhile in your code with "Table" you call the panel inside the ScrollView (namely scvList.Panel). In your code, scvList is defined in the Designer (unluckily I lost the original of your example "ScrollViewMultiSelect" and I am reconstructing it by memory). Instead, I put a Panel in the designer, say Panel1. Then I put the ScrollView (say scvList) on the Panel1 (who becomes its parent). I understand that this structure may be "questionable", but the underlying idea was to manage the background under the ScrollView, on Panel1. This is the reason of existence of Panel1. Anyway, what happens, despite being not a bug, may let someone waste time for such a silly situation. If I correctly guess, the decision of scrolling is taken by the system using the Whole surface of the ScrollView, while, having I inserted it in the panel, I was not seeing all the surface. All data were contained in the ScrollView (so no scroll was possible) but, being the ScrollView inserted on the Panel1 not with full height, bottom part was not visible. This generated the false idea that, despite not seeing everything in the ScrollView, no scroll happened.
Thanks for your attention.
 

klaus

Expert
Licensed User
Longtime User
Sorry for the misunderstanding.
I thought you were using the Table Class because in your first post you reference the LoadTableFromCSV routine which exist in the Table Class.
Be aware that when you load something onto a panel 100%x and 100%y are equal to Panel.Width and Panel.Height and not to Activity.Width and Activity.Height.

Link to ScrollViewMultiSelect.
 

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi Klaus. Perhaps a not interesting case, but my suspect is that it could happen not only inserting a ScrollView in a panel, but even in the activity. In fact the problem stays in the AddView with %y less than 100. I just thought that perhaps a graphic explanation could help. I illustrated my case in attached file. I repeat the problem: scrolling doesn't happen if the data is contained in the container of the ScrollView but not in the part of it which is actually shown. Of course mine is not a statement and I don't exclude to have not well understood the situation. In case, let me know your further comments. Thanks again.
 

Attachments

  • scroll1.png
    scroll1.png
    8.3 KB · Views: 248

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi. I prepared a test app, but, "as expected", it seems to work. So we can close this discussion. Luckily, as expected, it is not a bug. Just experience. The responsible of the problem is exactly what you said. In fact, if such height is not assigned an appropriate value, the scroll doesn't happen. The fact of inserting the ScrollView in a Panel, with less than 100%y was not the problem. The appropriate height value must be more than the "dip" height of a line multiplied by the number of items to be displayed. In the attached test app, I put 40 lines in the ScrollView, but, with Item height of 20 and ScrollView.Panel.Height=600 I only see 30. Modifyng values in the attached example, could help to understand the topic. Sometimes a "wrong example" perhaps may be useful to understand... Thanks
 

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi, Klaus
I don't know whether you are still following this issue or not. I was thinking that it was closed, but it is not so. As a matter of fact I still get bad results. Luckily I reproduced in the scrolltest example that I already posted.
Observe that in that example, Panel1, parent of ScrollView, is slightly smaller that the Activity. The ScrollView is inserted in Panel1, and its height is put to 600 dips. Each Row height is 20dip. Differently from the posted example, I put:

Panel1.AddView(SViTab, 0dip, 0, 100%x, 100%y) (in the example last 100% was 80%)

So, as I wrote, I expected to see 30 rows. Paradoxally it happens with the previous 80%y (that's why I thought the topic was closed )... now with 100%y I just see 27 rows ...
What am I missing? Thanks.
 

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
By the way, putting Panel1 height=to Activity.Height, in the Designer, the example shows 30 rows .. So the conclusion seems to be that Scrolling is calculated on the Activity, despite the ScrollView is inserted in the Panel..
 

klaus

Expert
Licensed User
Longtime User
You are not adjusting the height of the internal panel correctly.
You set the height to 250dip, but you add 14 items with a height of 20dip, so the height should be 280dip and not 250dip.
The code could look like this:
B4X:
Sub ShowTable
    Dim L As Label,i As Int,h As Int

    h=20dip
  
    SViTab.Initialize(0)        
    SViTab.Panel.Color=Colors.Black
  
    SViTab.Panel.Color = Colors.Black
  
    Panel1.AddView(SViTab, 0dip, 10%y, 100%x, 60%y)
  
    For i = 0 To 13
      L.Initialize("")
      L.Text = i
      SViTab.Panel.AddView(L, 0, i * h, 100%x, h)
    Next
    SViTab.Panel.Height = i * h
End Sub
No need to use an intermediate variable for the internal panel (Table = SViTab.Panel.
I replaced Table by SViTab.Panel.
 

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi, sorry Klaus. I never wrote 14, but 40. Anyway I am forced to insist on the concept. The following code:

Sub ShowTable
Dim L As Label,i As Int,h As Int
h=20
SViTab.Initialize(0)
SViTab.Panel.Height=600dip ' should show 30 lines
SViTab.Panel.Color = Colors.Red
Panel1.AddView(SViTab, 0dip, 0%y, 100%x, 100%y)
For i=0 To 40
L.Initialize("")
L.Text=i
L.Color=Colors.Red
SViTab.Panel.AddView(L,0,i*h,100%x,h)
Next
End Sub

should show 30 rows. I only see 27 of them. In the designer Panel1 height is 370. I don't see any relation among these numbers..
I already verified that, if the ScrollView is inserted directly in the Activity, things work. Anyway, I don't exclude to be wrong..
 

Attachments

  • ScrollTest.zip
    2 KB · Views: 240

klaus

Expert
Licensed User
Longtime User
You must replace this line
B4X:
Panel1.AddView(SViTab, 0dip, 0%y, 100%x, 100%y)
by this one
B4X:
Panel1.AddView(SViTab, 0, 0, Panel1.Width, Panel1.Height)
In the code 100%x and 100%y reference the screen.
If you load a layout onto a panel, 100%x and 100%y in the layout represent the panel width and height.

Attached two sample programs.
New: With Panel1.AddView(SViTab, 0, 0, Panel1.Width, Panel1.Height)
New1: With the scrollView loaded from a layout file onto a panel.
They include a solution you the scroll to problem.
 

Attachments

  • New.zip
    6.9 KB · Views: 248
  • New1.zip
    7.9 KB · Views: 251

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi, Thanks for your efforts. I still have problems. Let take new.zip as the basis for discussion. I modified your new.zip example. Moreover, let's forget the ScrollView inside the Panel. So I have put the scrollview inside the Activity, directly with the designer. A fairly normal situation. The table scrolls till the end, when the App opens. But, as I asked in this post, I cannot force the scrollview to scroll up a line... Take a glance at it if possible, and thanks a lot for your patience..
 

Attachments

  • New2.zip
    22.8 KB · Views: 239

klaus

Expert
Licensed User
Longtime User
What exactly do you want to do ?
Increasing the internal panel height after creation without adding something seems not working.
I had never tested this because for me there is no concrete use.
Attached a mofifyed version.
 

Attachments

  • New2.zip
    7.5 KB · Views: 231

Beja

Expert
Licensed User
Longtime User
Hi,
I opened your first zip file and manually pulled down the internal panel (from abstract designer) . it worked and I could see all the lines and even a blank area beneath them.
 

klaus

Expert
Licensed User
Longtime User
The behaviour is much more tricky.
It seems that after you add an item you are allowed to change the internal panel height only one time, later changes have no effect.
In the project in post#18, changing the height in btnAdd_Click (heigher or smaller) without adding a label has no effect.
Adding a label, the height changes.
Adding a label and removing it directly after and then changing the height works.
 
Top