To set the spacing using Recyclerview, you need to override the Recyclerview.itemdecoration class. Like the next need to implement, the spacing is only between the middle of the lattice and the bottom of the format there.
Paste_image.png
The implementation is simple because the effect is that each row has 3 squares, as long as the first format of each row has a left spacing of 0. The rest sets the left and bottom distances.
The code is as follows:
Public classSpaceitemdecoration extends Recyclerview.itemdecoration {Private intspace; PublicSpaceitemdecoration (intspace) { This. Space =space; } @Override Public voidgetitemoffsets (Rect outrect, view view, Recyclerview parent, recyclerview.state state) {//not the first grid has a left and bottom spacingOutrect.left =space; Outrect.bottom=space; //since each row has only 3, so the first is a multiple of 3, the left margin is set to 0 if(parent.getchildlayoutposition (view)%3==0) {Outrect.left=0; } }}
Android recyclerview using Gridlayoutmanager spacing settings