Skip to content

Instantly share code, notes, and snippets.

@jsaund
Created September 17, 2017 23:14
Show Gist options
  • Save jsaund/1287c8fbb345ad24be653759980bd437 to your computer and use it in GitHub Desktop.
Save jsaund/1287c8fbb345ad24be653759980bd437 to your computer and use it in GitHub Desktop.
Creating and using SnapHelper with RecyclerView
class MyActivity : AppCompatActivity {
override fun onCreate(savedInstanceState: Bundle?) {
val recyclerView = findViewById(R.id.list) as RecyclerView
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = ExampleAdapter()
LinearSnapHelper().attachToRecyclerView(recyclerView) // Configures the snap helper and attaches itself to the recycler view -- now items will snap to the center
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment