'Grid layout manager with dynamic item

I use grid layout manager but not working good for dynamic item

What I want:

enter image description here

or just like

enter image description here

And What it shows:

enter image description here



Solution 1:[1]

use StaggeredGridLayoutManager

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

Solution 2:[2]

Try this one

RecyclerView recyclerView = (RecyclerView) 
context.findViewById(R.id.recyclerview);
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context);
layoutManager.setFlexDirection(FlexDirection.COLUMN);
layoutManager.setJustifyContent(JustifyContent.FLEX_END);

https://github.com/google/flexbox-layout

recyclerView.setLayoutManager(layoutManager);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sasikumar
Solution 2 Amit pandey