Android Question [TIP][SOLVED] ScrollView, get current "inview zero position"

Cableguy

Expert
Licensed User
Longtime User
Hi guys...

From the title it may be somewhat difficult to understand what I'm asking...

I have a scrollview wich CAN be bigger that the screen, depending on user input...
In it I have several Panels to which I gave the ability to expand/colapse in the vertical axis. They act as menu Titles.
In these panels I have several labels placed in the horizontal axis.

I need to know the TOP property of a particular label, within its panel, independently of if the scroll view has been scrolled or not.

So If my panel is placed at 200dip in the vertical axis, and my label is at 10dip inside my panel, the I have a relative top value of 10dip (label to parent panel) but my panel, even though it is placed at 200dip, may NOT be presented to the user at that coordinate, because of the very useful behaviour of the scroll view...

I know we have a scrollPosition for the scrollview, but that points to Where???? the absolute (in view) zero, or the relative position of the scrollview (like giving me 200dip if my panel is within view)?
 

Cableguy

Expert
Licensed User
Longtime User
As I often do, while waiting for help, I end up helping myself...

So, how to get any view relative "inview" position inside a scrollview:
If the view you are trying to get the position of is a direct child of the Scrollview's inner panel, then:
B4X:
            myview.Top = v.Top - SV.ScrollPosition ' this places myview in the same vetical value as the v view
if it has a parent of its own, which is a child of the ScrollView's inner panel then:
B4X:
    Dim z As Panel = getParent(v) 'search for Klaus Views Utils thread, you'll find a getParent sub there
               myview.Top = (z.Top - SV.ScrollPosition) + v.top
 
Upvote 0
Top