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

Discussion in 'Additional libraries, classes and official updates' started by Erel, Sep 12, 2019.

  1. Erel

    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.

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Johan Hormaza

    Johan Hormaza Active Member Licensed User

  4. T201016

    T201016 Member Licensed User

    An interesting solution to a problem I was also thinking about. Good job:)
  5. Carlos marin

    Carlos marin Active Member Licensed User

    Hello everyone, this same function is possible but in a horizontal view?
  6. Erel

    Erel Administrator Staff Member Licensed User

    Yes, should work. Change it to: (untested)
    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 + 
    End If
    End Sub
    Johan Hormaza likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice