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

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

nngdEpSCwl.gif
 
An interesting solution to a problem I was also thinking about. Good job:)
 
Yes, should work. Change it to: (untested)
Code: Copy
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
 
Back
Top