调整android中的布局大小

时间:2011-09-04 15:32:20

标签: android-layout

我的布局中只有5个按钮。显示布局时我面临的问题是 - 布局的剩余空间被浪费而不是空。我想减小屏幕尺寸,使其看起来不是空白。

以下是我用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。

1 个答案:

答案 0 :(得分:1)

我认为这就是你想要的。

首先将根LinearLayout高度设为 * fill_parent * ,使其填满整个屏幕

然后将按钮放在另一个LinearLayout中,其中 android: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比例

相关问题