Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gap between two buttons in LinearLayout

In my app two button arranged vertically in LinearLayout. i want to provide a gap between two buttons. Please provide a solution...

my layout 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

thanks in advance

like image 494
Riskhan Avatar asked Dec 19 '12 06:12

Riskhan


4 Answers

Add a margin (android:layout_marginTop="50dp") to the top of 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> 
like image 133
urveshpatel50 Avatar answered Oct 16 '22 01:10

urveshpatel50


use android:layout_marginTop="10dp"

like image 28
Aamir Shah Avatar answered Oct 16 '22 02:10

Aamir Shah


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

like image 3
Chirag Avatar answered Oct 16 '22 03:10

Chirag


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"
/>
like image 3
Mudassar Shaheen Avatar answered Oct 16 '22 02:10

Mudassar Shaheen