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
.
Android: GridLayout spacing between items
Asked Answered
check this answer if it helps https://mcmap.net/q/471138/-gridlayout-not-gridview-spaces-between-the-cells –
Emmie
Possible duplicate of GridLayout(not GridView) - Spaces between the cells –
Brunhilde
These don't seem to be duplicates. This is about adding spacing; the other is about removing it. –
Ress
You can put margin to the buttons
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
Instead of adding margin to each buttons, use android:useDefaultMargins="true"
It is better than adding margin to each buttons!
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 other –
Uniform
You can put margin to the buttons
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.