Размер макета в Android - PullRequest
       0

Размер макета в Android

0 голосов
/ 04 сентября 2011

У меня ровно 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>

Есть ли способдостичь этого?

Адитья.

1 Ответ

1 голос
/ 04 сентября 2011

Я думаю, что это то, что вы хотите.

Сначала установите высоту 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

...