2
The way I recommend is to use the RecyclerView
along with a StaggeredGridLayoutManager
.
You’ll have something like:
RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler_view);
StaggeredGridLayoutManager staggeredLayoutManager =
new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recycler.setLayoutManager(staggeredLayoutManager);
Where the first parameter of StaggeredGridLayoutManager
is the number of columns.
Of course you can configure the strategy to fill the "gaps".
Then you can use the method setGapStrategy
with one of these constants:
GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS - Não tem documentação, mas ele provavelmente move os itens para ocupar os espaços
GAP_HANDLING_LAZY - Só ocupa os gaps quando houver scroll
GAP_HANDLING_NONE - Não faz nada, deixa o gap
Another issue is the spans
, in the LayoutParams
from the list item, you can define whether the item uses all the spans
or not, that is, define whether it occupies the entire line or not.
Then just use inside your Adapter
the LayoutParams.setFullSpan(boolean)
.
Of course you will have to implement a RecyclerView.Adapter
, which is a little different from implementing a BaseAdapter
for example.
For more details I recommend these fonts: