Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning wrap content in dimens

I want to support both small screens and large screens

I have an image view in my layout - that in small screens it needs a layout height of "wrap_content"

and in large screens it needs 400dp (wrap content is too small)

instead of creating another layout, i wanted to create a dimension

<dimen name="layout_height">wrap_content</dimen>

<dimen name="layout_height">400dp</dimen>

and assign them to the right folders and in my imageview write

layout_height=@dimen/layout_height

is this possible in any way, without creating another layout ?

like image 530
Lena Bru Avatar asked Jun 19 '14 07:06

Lena Bru


2 Answers

To assign wrap_content or match_parent from resources you need to create these 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/wrap_content</dimen>
like image 167
Dangiras Rackauskas Avatar answered Oct 07 '22 23:10

Dangiras Rackauskas


you can have a different style for small and large screen, overriding the layout_height property. Unfortunately you can not set wrap_content inside dimen

like image 21
Blackbelt Avatar answered Oct 08 '22 00:10

Blackbelt