Created
September 17, 2017 23:14
-
-
Save jsaund/1287c8fbb345ad24be653759980bd437 to your computer and use it in GitHub Desktop.
Creating and using SnapHelper with RecyclerView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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