7

私のアプリでは、LinearLayout に垂直に配置された 2 つのボタンがあります。2 つのボタンの間にギャップを設けたい。解決策を教えてください...

次のように私のレイアウト

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

画像

ここに画像の説明を入力

前もって感謝します

4

4 に答える 4

17

2 番目のボタンの上部に余白 (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> 
于 2012-12-19T06:51:17.493 に答える
6

使用するandroid:layout_marginTop="10dp"

于 2012-12-19T06:50:34.453 に答える
3

android:layout_marginTop="10.0dip"2番目のボタンに使用します。

于 2012-12-19T06:49:46.900 に答える
3

このコードを 2 番目のボタンに使用します

<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"
/>
于 2012-12-19T06:51:46.303 に答える