Well first you need to work out the width of the screen, incase you are using unbound scrolling the top left of layout is no longer 0, so to get the screen width use viewportRight - viewportLeft.
Now you need to get the width of all your blocks put together, so combined block width = block.width * number of blocks on a row.
Then you need to work out how much space is left over for your gaps in-between blocks and divide that by number of blocks, so gap = (screen width - combined block width) / number of blocks on a row.
Now to do the actual spacing, you can arrange blocks by their IIDs using the optional instance parameter block(IID).expression, so you would do - repeat number of block times, set block(loopindex).x to viewportLeft+(blockwidth*loopindex)+gap
Same for height.
I didn't test it so dont know if it works as intended.