0

How to you make 4 fixed size buttons in an horizontal LinearLayout fill the space of that layer horizontally, letting the Android put the needed space betetween those buttons to fill that space ?

Oliver
  • 23,072
  • 33
  • 138
  • 230

2 Answers2

7

Are you searching for something like this?

<?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="fill_parent"
android:background="#FFF"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical" >
    </LinearLayout>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical" >
    </LinearLayout>

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical" >
    </LinearLayout>

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

Rahmathullah M
  • 2,676
  • 2
  • 27
  • 44
0

If I understood correctly, you want to make those 4 buttons take equal space in a horizontal LinearLayout, if so, then add: android:layout_weight="1" in the XML layout, for each 4 buttons.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
  • No, that makes the buttons bigger. I want the space beetween those buttons to adapt and grow to fill the space. I want the space beetween the buttons to act as filler. – Oliver Sep 21 '12 at 22:53