Android Question Get scrolled/current position of panel in scrollview

bitben

Member
Licensed User
Longtime User
hi,

i have an scrollview element filled with a few panels. from every panel, when clicked, i want to start an animation, so i need the top position of every panel. as far as good, get it over the touch event. but when i scroll down and click on a panel, which was further down, the animation starts not on the current position, it starts on the "initialized" position. so my question is how i get current position from a clicked panel wherever the scrollposition is? sorry for my english, i hope you understand :)
 

bitben

Member
Licensed User
Longtime User
This seems to be a solution, i'll try it on weekend and give a feedback
sorry for my late answer
 
Upvote 0

bitben

Member
Licensed User
Longtime User
Ok i implemented your CustomListView, but i can't figure out how to get the position of every item.
Here is a snippet, a panel (Panel2) should appear over an selected item and move away, but the panel appears always on top of the CustomView, maybe i am blind, what is my fault?
I use panel.top and this only brings 0, what should i use?

B4X:
Sub deviceList_ItemClick (Index As Int, Value As Object)
    Dim p As Panel = CustomView1.GetPanel(Index)
    Dim lbl1 As Label = p.GetView(0)
    Dim lbl2 As Label = p.GetView(1)
    a1.InitializeAlpha("animate", 1, 0)
    a1.Duration=500
    [...]
    appear = Array As Animation(a1)
    Panel2.Left = CustomView1.AsView.Left
    Panel2.Top = p.Top '<- ?
    [...]
    Panel2.Visible = True
    For i = 0 To appear.Length - 1
        appear(i).start(Panel2)
    Next
End Sub
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Add this subroutine to the CustomListView Class and call it instead of calling GetPanel.....
B4X:
'Returns the top position of the Panel stored at the specified index.
Public Sub GetPanelPosition(Index As Int) As Int
    Dim top As Int
    Dim p As Panel
    For i = 0 To Min(Index - 1, items.Size - 1)
        p = panels.Get(i)
        top = top + p.Height + dividerHeight
    Next
    top = top - sv.ScrollPosition
    Return top
End Sub
 
Upvote 0
Top