Hock
Hock

Reputation: 157

How to fix supply a layout_width attribute in Android

In my application i want use RelativeLayout and for set size to this i use dimens .
I write my XML code such as below :

            <RelativeLayout
                android:id="@+id/listItemAuction_productImgLay"
                android:layout_width="@dimen/size120New"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginBottom="@dimen/padding5"
                android:layout_marginRight="@dimen/padding5"
                android:layout_marginTop="5dp">
            </RelativeLayout>

Dimen size : <dimen name="size120New">120</dimen>

But when run application show me below error on Logcat :

java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_width attribute.

How can i fix it and us dimes?

Upvotes: 0

Views: 31

Answers (1)

Hamzah Malik
Hamzah Malik

Reputation: 2570

Your width dimenension needs a unit

120 on its own is meaningless. You probably wanted 120dp. A dp is a unit of physical measurement, independent of resolution and this is how android maintains compatiblity with different devices.

EG:

<dimen name="size120New">120dp</dimen>

There are also other units, this answer explains well: https://stackoverflow.com/a/2025541/2762277

Upvotes: 2

Related Questions