Android: GridLayout spacing between items
Asked Answered
F

2

31

I have a grid layout which is filled with buttons. I want the buttons to be more distant from each other, what code should I write? I tried to search for it but only found a solution for GridView, not GridLayout.

Farleigh answered 8/2, 2016 at 13:6 Comment(3)
check this answer if it helps https://mcmap.net/q/471138/-gridlayout-not-gridview-spaces-between-the-cellsEmmie
Possible duplicate of GridLayout(not GridView) - Spaces between the cellsBrunhilde
These don't seem to be duplicates. This is about adding spacing; the other is about removing it.Ress
A
25

You can put margin to the buttons

Ap answered 8/2, 2016 at 13:8 Comment(3)
what if I have to dynamically rearrange columns and rows? the margin will mess everything up in that case.Comber
margin will not show equal spacing on each side. For example: margin of 2dp on each item will show 2 dp on each side but item after will also have 2 dp on each side. Making it total of 4dp space in between now.Escort
You can put only margin end on the individual items to avoid duplication of margins.Snuffer
U
28

Instead of adding margin to each buttons, use android:useDefaultMargins="true"

It is better than adding margin to each buttons!

Uniform answered 13/2, 2019 at 5:45 Comment(2)
this doesn't answer the main question. Does this answer my doubts on the first answer? In that case you should've commented the answer.Comber
Even if you re-arrange items they will stay distinct and wont mess up with each otherUniform
A
25

You can put margin to the buttons

Ap answered 8/2, 2016 at 13:8 Comment(3)
what if I have to dynamically rearrange columns and rows? the margin will mess everything up in that case.Comber
margin will not show equal spacing on each side. For example: margin of 2dp on each item will show 2 dp on each side but item after will also have 2 dp on each side. Making it total of 4dp space in between now.Escort
You can put only margin end on the individual items to avoid duplication of margins.Snuffer

© 2022 - 2024 — McMap. All rights reserved.