I couldn\'t find any better example for using RecyclerView with StaggeredGridLayoutManager. Not even in Android Docs.
Q
Assuming that you've already created an adapter and initialized the RecyclerView, the following code should do what you're looking for.
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(staggeredGridLayoutManager);
For further reference and documentation please check the following link: https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html