2011-09-04 98 views
0

我的佈局中恰好有5個按鈕。我在顯示佈局時遇到的問題是 - 佈局的剩餘空間被浪費,而不是空的。我想縮小屏幕尺寸,使其看起來沒有半邊空白。調整Android中的佈局

以下是代碼我已經寫在XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 
    <!-- I want to eat button --> 
    <Button android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="@string/iWantToEat" 
    android:textSize="20sp" android:id="@+id/iWantToEat"> 
    </Button> 

    <!-- Categories --> 
    <Button android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="@string/Categories" 
    android:textSize="20sp" android:id="@+id/Categories"> 
    </Button> 

    <!-- Explore/Discover --> 
    <Button android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="@string/Explore" 
    android:textSize="20sp" android:id="@+id/Explore"> 
    </Button> 

    <!-- Search --> 
    <Button android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="@string/Search" 
    android:textSize="20sp" android:id="@+id/Search"> 
    </Button> 

    <!-- My Favorites --> 
    <Button android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="@string/myFavourites" 
    android:textSize="20sp" android:id="@+id/myFavourites"> 
    </Button> 

</LinearLayout> 

有沒有辦法實現呢?

Adithya。

+0

我不理解......你想要的5個按鈕來填充整個屏幕?? –

+0

no ..我希望只有這些按鈕具有特定尺寸(比如20sp),但希望屏幕尺寸減小,以便佈局僅顯示這5個按鈕,佈局中不會留下空白區,因爲它通常會在下面進行那些按鈕。 – Adithya

+0

所以你可以在按鈕之間有空格... –

回答

1

我認爲這是你想要的。

首先使根的LinearLayout高度* FILL_PARENT *以便它填充整個屏幕

然後把按鈕另一個的LinearLayout內側機器人:layout_weight =「1」如下所示

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    > 
     <!-- I want to eat button --> 
     <Button android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textSize="20sp" android:id="@+id/iWantToEat"> 
     </Button> 
    </LinearLayout> 

它劃分屏幕以1:1:1:1:1的比例

+0

做這個工作...? –