Skip to content
Beka Westberg edited this page Feb 5, 2020 · 1 revision

A SnapHelper is a type of object that can be attached to a RecyclerView to make the items in the layout "snap" to a certain position.

LoopingSnapHelper

The looping-layout project provides its own implementation of the SnapHelper call LoopingSnapHelper, which deals with the particular quirks of the LoopingLayoutManager.

You can attach this SnapHelper to your RecyclerView by doing the following:

class MyActivity : AppCompatActivity() {
    private lateinit var recyclerView: RecyclerView
    private val snapHelper = LoopingSnapHelper()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        recyclerView = findViewById(R.id.recycler)

        // etc...

        snapHelper.attachToRecyclerView(recyclerView)
    }
}

The above code is written in kotlin.

Currently the LoopingSnapHelper uses a less-than-optimal animation strategy because of limitations in the Android source code. But it does work, and there are plans to improve it! You can follow Issue #7 for further updates.

Clone this wiki locally