Assigning 'wrap_content' or '-2' to dimension

c00p3r.web picture c00p3r.web · Jul 8, 2013 · Viewed 8.6k times · Source

I want to create a dimension that would be equal to 'wrap_content' constant.

So according to developer.android.com Reference I write:

<dimen name="horizontal_border_height">-2</dimen>

But ADT says:

Error: Integer types not allowed (at 'horizontal_border_height' with value '-2')

Asigning 'wrap_content' value generates error too.

What am I doing wrong? Any ideas how to make it work?

Answer

Dangiras Rackauskas picture Dangiras Rackauskas · Dec 9, 2015

To use wrap_content or match_parent you need to create following items in dimens.xml file:

<item name="match_parent" format="integer" type="dimen">-1</item>
<item name="wrap_content" format="integer" type="dimen">-2</item>

Then you can simply use it like this:

<dimen name="layout_height">@dimen/match_parent</dimen>
<dimen name="layout_width">@dimen/wrap_content</dimen>