使用 StaggeredGridLayotManager?

Work With StaggeredGridLayotManager?

我想使用 StaggeredGridLayoutManager 来创建一个包含两列且每行包含 3 个部分的垂直列表。 我具体应该怎么做?

假设你想把它附加到一个recyclerview,你可以这样添加

  StaggeredGridLayoutManager staggeredGridLayoutManager=new 
  StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(staggeredGridLayoutManager);

其中 recyclerView 是 RecyclerView 对象

尝试使用 StaggeredGridLayotManager

private StaggeredGridLayoutManager gaggeredGridLayoutManager;
RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);    
gaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, 1);
recyclerView.setLayoutManager(gaggeredGridLayoutManager)

这里是教程linkworking with StaggeredGridLayotManager