Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The required layout_width and layout_height attributes are missing

I've got the following layout xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<item android:id="@+id/descriptions_menu"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:icon="@drawable/ic_menu_info_details"
      android:title="Toggle Descriptions On/ Off" />

<item android:id="@+id/settings_menu"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:icon="@drawable/ic_menu_preferences"
      android:title="Settings" />

But I keep getting this error: The required layout_width and layout_height attributes are missing

This is reported on lines 2, 9, 10. It seems totally bizarre. It's in an old project (>5 years) that I'm trying to resurrect.

like image 352
MattyW Avatar asked Mar 29 '15 08:03

MattyW


2 Answers

i think menu layout is not valid in res/layout, you need to place it in res/menu as stated in the documentation

To define the menu, create an XML file inside your project's res/menu/ directory and build the menu with the following elements

and you can inflate it using MenuInflater.inflate()

like image 173
Yazan Avatar answered Nov 17 '22 18:11

Yazan


If this is the menu file then you have to close the menu tag at the end of file, Make sure this file is in res > menu folder > menu file.

<?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <item android:id="@+id/descriptions_menu"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:icon="@drawable/ic_menu_info_details"
          android:title="Toggle Descriptions On/ Off" />

    <item android:id="@+id/settings_menu"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:icon="@drawable/ic_menu_preferences"
          android:title="Settings" />
    </menu>
like image 39
Prashant Bhoir Avatar answered Nov 17 '22 17:11

Prashant Bhoir