Scrollview will not Scroll

vaughanwj

Member
Licensed User
Longtime User
I must be missing something fundamental about Scrollview. I would have thought the thing that it would fundamentally do is scroll without too much effort, so clearly I am missing something fundamental.

I have looked at the helpscrollview example without success.
I have tried adding my images via the designer, then via the code.

Basically what I want is this: I need to be able to scroll a series of several images and text of variable length off the page vertically. I am willing to start with fixed length if that helps.

Here is what I have done.
Created a new Activity ("localView"), added a scrollview (ScrollView1) to it, then in code, added 20 images , (10 rows of 2) that scroll off the page, like this:

B4X:
        Dim t,w,h As Int
   w = 80
   h = 80
   t = 60
   ScrollView1.Panel.Height = 800
   ScrollView1.Panel.AddView(imgSun,0,t,w,h)
   ScrollView1.Panel.AddView(imgSunSign,w+10,t,w,h)
   t = t + h + 10
   ScrollView1.Panel.AddView(imgMoon,0,t,w,h)
   ScrollView1.Panel.AddView(imgMoonSign,w+10,t,w,h)
   t = t + h + 10
...and so on. All the images are where they are supposed to be, but it will not scroll so I can't see the bottom ones.

As I said, there must be something fundamental I'm missing. I've added doevents and ScrollView1.FullScroll(True) in the hopes I could wake it up but to no avail. Height, InnerHeight and Panel (which I'm not clear on) Height are all set to 800.

Please let me know where the facepalm move is..

Thanks,
Vaughan
:sign0104:
 

vaughanwj

Member
Licensed User
Longtime User
Remove
ScrollView1.Panel.Height = 800
at the beginning

and add this code
t = t + h + 10
ScrollView1.Panel.Height = t

at the end.

Your ScrollView1.Panel.Height value is too small.

Best regards.

Thanks Klaus, I just tried your solution, no change unfortunately. Any other ideas?
 
Upvote 0

vaughanwj

Member
Licensed User
Longtime User
Post your project so we could test it in the same conditions as you do.
IDE menu Files / Export As Zip.

Best regards.

I had a feeling you were going to ask that ;) I can't really do that yet without genericizing the project.

But I do see something different that may be the key. In your helpscrollview project, you have this code:

B4X:
        pnlHelp.Initialize("")
   Activity.AddView(pnlHelp, 0, 0, 100%x, 100%y)
   Activity.Title = "HelpScrollView"
   pnlHelp.LoadLayout("Main")
   scvHelp.Panel.LoadLayout("ScrollView")

I'm trying to understand what the Panel piece does. In mine the layout just has the scrollview on it, and I call it like this:

B4X:
Activity.LoadLayout("localView")
setupScrollView

setupScrollView adds the image views as we looked at earlier. Is this where I'm missing something?
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
I'm trying to understand what the Panel piece does. In mine the layout just has the scrollview on it...

Yep. Same question to me. E.g. the panel is 400 by 800 and I put a scrollview on it with 400 by 1600: In my mind a "panel" is like a "Desktop" to me with a specific size (max fullscreen). Then, I put a scrollview on it with much larger dimensions. That iritates me at the moment.

@Klaus #1: Is that the best practice in Android to handle "large screens" or is it some kind of "workaround" like an override? Could you explain the relation between physical screen size of the device, panel size and the size of a scrollview?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
@vaughanwj

Without seeing more code it's very difficult to give you concrets answers.
We must guess to find out what errors you 'could' have made.
Seeing the whole code code or at least a smaller project showing the problem we 'can' see where and what you did wrong by testing the program in the same conditions as you do!

You say my suggestion doesn't work, but you don't show how you did it.
So I can't know if you did it right.

In your code in post #1 you set ScrollView1.Panel.Height = 800
That means that the ScrollViews internal panel height is 800 pixels.
But you have 8 rows with images 80 pixel heigh and with 10 pixel space.
So the panel heigt should be at least 10 * 80 + 11 * 10 = 910 pixels !
That's why I told you to add
t = t + h + 10
ScrollView1.Panel.Height = t
at the end.

Then what value has ScrollView1.Height ?
What's your device 100%y value ?
etc.

By the way you should use dip (density independent pixels) values instead of absolute pixels.

Best regards.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
@Klaus Matle,

Any view can be bigger than the screen !
We have different sizes:
- the screen size, the size of the whole screen
- the Activity size, the area of the screen available for the user (developper) this is given by Activity.Height and Activity.Width or 100%y and 100%x.
If a view is bigger than the screen only a part of it is displayed on the activity area. The visible part of it can be changed with the Left and Top properties of the view.
A Panel is a container for other views like the Activity but it can be bigger than the activity area !
A ScrollView is a special container with a visible area defined by the ScrollView.Height and ScrollView.Width properties. Thes values must not exceed the activity area!
The ScrollView has an internal Panel with a height that can be bigger than ScrollView.Height and the scrolling is handled by the operatiing system if ScrollView.Panel.Height is bigger than ScrollView.Height.

You can't add directly views to a ScrollView in the Designer.
But you can define in the Designer a seperate layout with one Panel, heigher than the activity area, and add the views on this Panel and load the layout file into the ScrollView.Panel. In the Designer you can play with the Top property of the Panel to show the relevant part of it to add the views. In this case don't forget to reset the Top property to 0 befor compiling.

Best regards.
 
Upvote 0
Top