How to split two buttons in LinearLayout

In my application, two buttons are arranged vertically in LinearLayout. I want to provide a gap between the two buttons. Please provide a solution ...

my layout is as follows

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="10dp" > <Button android:id="@+id/btnAction1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/cool_button" android:text = "HiText1" /> <Button android:id="@+id/btnAction2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/cool_button" android:text="HiText2" android:layout_below="@id/btnAction1" /> </LinearLayout> 

image

enter image description here

early

+7
source share
4 answers

Add a marker (android: layout_marginTop = "50dp") to the top of the second button:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="10dp" > <Button android:id="@+id/btnAction1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/cool_button" android:text = "HiText1" /> <Button android:layout_marginTop="50dp" android:id="@+id/btnAction2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/cool_button" android:text="HiText2" android:layout_below="@id/btnAction1" /> </LinearLayout> 
+17
source

use android:layout_marginTop="10dp"

+6
source

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

+3
source

use this code for your second button

 <Buttonandroid:id="@+id/btnAction2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/cool_button" android:text="HiText2" android:layout_marginTop="15dp" /> 
+3
source

All Articles