No good example about RecyclerView and StaggeredGridLayoutManager in Android Docs

前端 未结 3 558
难免孤独
难免孤独 2020-11-27 14:20

I couldn\'t find any better example for using RecyclerView with StaggeredGridLayoutManager. Not even in Android Docs.

Q

3条回答
  •  庸人自扰
    2020-11-27 15:14

    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

提交回复
热议问题