I am trying android programming for the first time and want to create a calculator program to get a foothold. My problem is that I can’t place buttons on the same row without having them right next to each other. I would like some space between buttons that are next to each other.
Right now I have 3 buttons on the same row by changing the linearlayout to horizontal.
I tried messing with different xml elements for button, like android:layout_width/margin, but all I have been able to do is move a button below another button.
Looking into it I understand that I can’t freely move buttons because different android phones have different screen sizes, but I can’t imagine that there wouldn’t be a way to move button_1 10% away from the left side of the screen, button_2 50% away from the left side of the screen, and button_3 10% away from the right.
You could use a TableLayout, which seems more appropriate in that case. You can also use a LinearLayout with a weight of 1 for each button, and the margin or padding you want. Just don’t forget to set the width to 0 when you’re using weights on a horizontal LinearLayout.