B4A Library [B4X] SnapCLV - Move to the nearest item

Erel

Administrator
Staff member
Licensed User
SnapCLV is a very simple class that adds a "snap" feature to xCLV in vertical mode. When the user stops scrolling the list the list scrolls to the nearest item so the top item will not be partially hidden.

It is compatible with B4A, B4i and B4J

Note that you need to call snap.ScrollChanged from the ScrollChanged event.
 

Attachments

Erel

Administrator
Staff member
Licensed User
Yes, should work. Change it to: (untested)
B4X:
Private Sub SnapCLV (Offset As Int)
   Dim i As Int = mCLV.FirstVisibleIndex
   If i < 0 Then Return
   If Offset + mCLV.sv.Width >= mCLV.sv.ScrollViewContentWidth Then Return
   Dim item As CLVItem    = mCLV.GetRawListItem(i)
   Dim visiblepart As Int = item.Offset + item.Size - Offset
   If visiblepart / item.Size > 0.5 Then
       mCLV.ScrollToItem(i)
   Else
       mCLV.ScrollToItem(i + 1)
   End If
End Sub
 
Top