2017-04-13 35 views
-3

如何使用RecyclerView在每行显示多个ImageView?例如,将图像显示为4X6像iPhone照片应用程序。 我应该手动调整ViewHolder以显示一定数量的ImageView?还是有更聪明的方法来做到这一点?使用RecyclerView每行保存多个图像

回答

0

您应该使用带有RecylerView的网格。

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recylerId); 
     recyclerView.setLayoutManager(new GridLayoutManager(this, numberOfImagesInARow)); 
+0

这是有道理的,一定要去尝试一下以后,谢谢! – x1uan

0

您可以使用GridLayoutManagerStaggeredGridLayoutManagerRecyclerView, 显示在同一行上的多个图像。

// Using GridLayoutManager 
recyclerView.setLayoutManager(new GridLayoutManager(this, numberOfColumns)); 

// Using StaggeredGridLayoutManager 
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(numberOfColumns, StaggeredGridLayoutManager.VERTICAL)); 

documentation

教程链接:

  1. https://android--code.blogspot.com/2015/12/android-recyclerview.html
  2. https://inducesmile.com/android/android-gridlayoutmanager-with-recyclerview-in-material-design/