简体   繁体   中英

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

在此处输入图片说明

thanks in advance

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> 

使用android:layout_marginTop="10dp"

在第二个按钮上使用android:layout_marginTop="10.0dip"

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"
/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM