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

  • SnapCLV.zip
    9.8 KB · Views: 575

Erel

B4X founder
Staff member
Licensed User
Longtime User
nngdEpSCwl.gif
 

T201016

Active Member
Licensed User
Longtime User
An interesting solution to a problem I was also thinking about. Good job:)
 

Erel

B4X founder
Staff member
Licensed User
Longtime 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