Reputation: 601
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.
Upvotes: 1
Views: 442
Reputation: 586
I think you are looking for layout_margin
, layout_marginTop
, layout_marginLeft
, layout_marginBottom
and layout_marginRight
attributes
Upvotes: 0
Reputation: 41858
Perhaps you are looking for padding.
http://developer.android.com/reference/android/widget/Button.html
You can use android:padding, android:paddingRight, android:paddingLeft, android:paddingTop, android:paddingBottom
Upvotes: 0
Reputation: 39013
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.
Upvotes: 2