Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private CustomListView1 As CustomListView
Private xui As XUI
Public ScrollChangedIndex As Int
Private InactiveDuration As Int = 200
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("1") 'use the same layout as what Erel has in the SnapCLV example
For i = 1 To 50
Dim p As B4XView = xui.CreatePanel("")
p.Color = Rnd(0xff000000, 0xffffffff)
p.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width, Rnd(200dip, 300dip))
CustomListView1.Add(p, "")
Next
End Sub
Sub CustomListView1_ScrollChanged (Offset As Int)
ScrollChanged (Offset)
End Sub
Public Sub ScrollChanged (Offset As Int)
ScrollChangedIndex = ScrollChangedIndex + 1
Dim MyIndex As Int = ScrollChangedIndex
Sleep(InactiveDuration)
If ScrollChangedIndex = MyIndex Then
SnapCLV(Offset)
End If
End Sub
Private Sub SnapCLV (Offset As Int)
Dim i As Int = CustomListView1.FirstVisibleIndex
If i < 0 Then Return
If Offset + CustomListView1.sv.Height >= CustomListView1.sv.ScrollViewContentHeight Then Return
Dim item As CLVItem = CustomListView1.GetRawListItem(i)
Dim visiblepart As Int = item.Offset + item.Size - Offset
If visiblepart / item.Size > 0.5 Then
CustomListView1.ScrollToItem(i)
Else
CustomListView1.ScrollToItem(i + 1)
End If
End Sub