Snap RecyclerView: Center Target Child View or ViewPager Full View Display

LinearSnapHelper, PagerSnapHelper


The implementation will snap the center of the target child view to the center of the attached RecyclerView

val snapHelper = LinearSnapHelper()snapHelper.attachToRecyclerView(recylerView)


PagerSnapHelper can help achieve a similar behavior to ViewPager. Set both RecyclerView and the items of the RecyclerView.Adapter to have ViewGroup.LayoutParams.MATCH_PARENT height and width and then attach PagerSnapHelper to the RecyclerView using SnapHelper.attachToRecyclerView(RecyclerView).

val snapHelper = PagerSnapHelper()snapHelper.attachToRecyclerView(recylerView)

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.