Reputation: 2975
I have exactly 5 buttons in my layout. The problem i am facing while displaying the layout is - the remaining space of the layout is being wasted rather is empty. I wanted to reduce the screen size so that it didn't look half-way blank.
Following is the code i have written in the 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>
Is there a way to achieve it ?
Adithya.
Upvotes: 0
Views: 267
Reputation: 7609
I think this is what you want.
First make the root LinearLayout height to *fill_parent* so that it fills the entire screen
Then put the buttons inside another LinearLayout with android:layout_weight="1" as shown below
<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>
It divide the screen to 1:1:1:1:1 ratio
Upvotes: 1