Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Element shape doesn't have required attribute android:layout_height

Tags:

android

xml

I'm using a shape element to put as the background of a view, doing as this SO question. I'm using Android Studio and it tells me that...

Element shape doesn't have required attribute android:layout_height

Element shape doesn't have required attribute android:layout_width

The code is as follows:

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

<solid android:color="@color/darkBrown"/>
<stroke android:layout_width="match_parent" android:layout_height="match_parent"/>
<corners android:radius="10dip"/>
<padding android:left="0dip" android:right="0dip" android:top="0dip" android:bottom="0dip"/>

</shape>

So basically my question: why do I get this error if shapes technically don't need these attributes? How can I tell android to stop marking it as an error or how can I avoid it?

Thank you.

SOLVED: The reason was because it wasn't inside the drawable folder.

EDIT: Yes I'm aware the stroke part is incorrect.

like image 276
Lorenz Avatar asked Jul 31 '15 17:07

Lorenz


2 Answers

The reason the error was shown is because it wasn't inside the drawable folder. (It moved automatically to layout when I renamed the drawable folder after a typo.)

like image 127
Lorenz Avatar answered Sep 23 '22 06:09

Lorenz


Here is an example of what a shape should look like:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
    android:radius="14dp"
    />
<solid
    android:color="#ADD8E6"
    />
<padding
    android:left="0dp"
    android:top="0dp"
    android:right="0dp"
    android:bottom="0dp"
    />
<size
    android:width="100dp"
    android:height="60dp"
    />
<stroke
    android:width="3dp"
    android:color="#ADD8E6"
    />

</shape>
like image 28
Kristy Welsh Avatar answered Sep 22 '22 06:09

Kristy Welsh