Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning 'wrap_content' or '-2' to dimension

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?

like image 230
c00p3r.web Avatar asked Jul 08 '13 11:07

c00p3r.web


4 Answers

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>
like image 111
Dangiras Rackauskas Avatar answered Nov 03 '22 01:11

Dangiras Rackauskas


Use this, it works for me

<integer name="custom_wrap_content">-2</integer>
<dimen name="horizontal_border_height">@integer/custom_wrap_content</dimen>

like image 17
Swetank Avatar answered Nov 03 '22 00:11

Swetank


Please use "-2dp" in dimension instead of "-2".
That is, just add dp after -2.

like image 16
patel Avatar answered Nov 03 '22 00:11

patel


Check out app resources API guide and you can see supported unites for a dimension value. You can't use dimension to pass a wrap_content as a Views dimension.

like image 6
Vladimir Radenković Avatar answered Nov 03 '22 00:11

Vladimir Radenković