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?
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>
Use this, it works for me
<integer name="custom_wrap_content">-2</integer>
<dimen name="horizontal_border_height">@integer/custom_wrap_content</dimen>
Please use "-2dp" in dimension instead of "-2".
That is, just add dp after -2.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With