Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

put space between android buttons

<Button
    android:id="@+id/o_pharmacy"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/p2"
    android:text="@string/o_pharmacy"
    android:textSize="26sp" />

<Button
    android:id="@+id/lab"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/lab"
    android:text="@string/lab"
    android:textSize="26sp" />

<Button
    android:id="@+id/i_pharmacy"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/p1"
    android:text="@string/i_pharmacy"
    android:textSize="26sp" />

I tried above code to display 3 buttons in Liner layout. It works but I need to put space between the two buttons.

like image 607
Dilshi Avatar asked Aug 03 '13 04:08

Dilshi


People also ask

How do I change the space between buttons in android?

The best is to use android:layout_marginTop="10dp" in your XML activity as this gives accurate spacing between that button and the other button or widget. Repeat this for rest of the buttons.

How do you put a space between two buttons in XML?

Use android:layout_marginTop="10.0dip" on second button.


3 Answers

android:layout_margin="10dp"

for each button

like image 80
Chor Wai Chun Avatar answered Oct 19 '22 19:10

Chor Wai Chun


If the orientation of your LinearLayout is vertical, use

android:layout_marginTop="10dp"

otherwise, use

android:layout_marginLeft="10dp"
like image 35
Tarsem Singh Avatar answered Oct 19 '22 18:10

Tarsem Singh


<Button
    android:id="@+id/o_pharmacy"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/p2"
    android:text="@string/o_pharmacy"
    android:textSize="26sp" />

<Button
    android:id="@+id/lab"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="25dp"
    android:drawableLeft="@drawable/lab"
    android:text="@string/lab"
    android:textSize="26sp" />

<Button
    android:id="@+id/i_pharmacy"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="25dp"
    android:drawableLeft="@drawable/p1"
    android:text="@string/i_pharmacy"
    android:textSize="26sp" />

Try this.

like image 4
nilkash Avatar answered Oct 19 '22 17:10

nilkash