0

I am trying to make a vertical list of 5 buttons which are evenly spaced out it the following format:

(Button1)

(Button2)

(Button3)

(Button4)

(Button5)

Where the buttons are also centered.

However I am only getting a blank grey screen.

I have the following code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

<Button
    android:id="@+id/buttonstock"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "1"
    android:text="@string/button_stock" 
     android:textSize="60sp"
     android:gravity="center">

 <View
        android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "1"
    android:gravity="center"/>

<Button
    android:id="@+id/buttonproducts"
          android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "1"
    android:text="@string/button_products"
     android:textSize="60sp"
     android:gravity="center" />

<View
  android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "1" 
    android:gravity="center"/>

<Button
    android:id="@+id/buttonsupplies"
         android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "1"
    android:text="@string/button_supplies"
    android:textSize="60sp"
    android:gravity="center" />

<View
       android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "1" 
    android:gravity="center"/>

<Button
    android:id="@+id/buttonsuppliers"
       android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "1"
    android:text="@string/button_suppliers"
     android:textSize="60sp"
     android:gravity="center" />

<View
          android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "1"
    android:gravity="center" />

<Button
    android:id="@+id/buttonsettings"
        android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "1" 
    android:text="@string/button_settings" 
     android:textSize="60sp"
     android:gravity="center"/>

</Button>
</LinearLayout>

I am also getting an error message on all of the buttons and views weight attribute saying:

Invalid layout param

However, I am not sure if this is part of the problem?

double-beep
  • 5,031
  • 17
  • 33
  • 41
user3166793
  • 27
  • 2
  • 3
  • 8

2 Answers2

2

Try this-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <Button
        android:id="@+id/buttonstock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:text="button_stock"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonproducts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:text="button_products"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonsupplies"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:text="button_supplies"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonsuppliers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:text="button_suppliers"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonsettings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:text="button_settings"
        android:textSize="20sp" />

</LinearLayout>
amit singh
  • 1,407
  • 2
  • 16
  • 25
1

You need to set the LinearLayout's height to match_parent also. If it is wrap_content it will look at it's children. They are all 0dp so it will also be 0dp and thus not visible.

PurkkaKoodari
  • 6,703
  • 6
  • 37
  • 58