簡體   English   中英

如何在LinearLayout中的兩個按鈕之間分隔

[英]How to gap between two buttons in LinearLayout

在我的應用中,兩個按鈕在LinearLayout中垂直排列。 我想在兩個按鈕之間提供一個間隙。 請提供解決方案...

我的布局如下

<?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> 

圖片

在此處輸入圖片說明

提前致謝

在第二個按鈕的頂部添加一個邊距(android:layout_marginTop =“ 50dp”):

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

使用此代碼作為第二個按鈕

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM