Noya
Noya

Reputation: 3899

Android Layout: use dimen just for some resolution

I'm trying to have an image which preserves its size in all the resolution except one... what i would like is to use the "wrap_content" attribute for height and override it with a dimen attribute but just for a particular case (like values-xlarge). I did like this:

 <ImageView android:id="@id/image_frame"
    android:layout_width="match_parent"
    android:layout_height="@dimen/overlayImageHeight" />

But of course it crashes if i don't define the overlayImageHeight in all the dimen.xml files. I tried to put a "wrap_content" string for other dimen.xml files but again it fails since dimen files just accept numeric values inside.

Is there a way to define this behaviour inside an xml file? Other way to do it programmatically?

Any help appreciated!

Upvotes: 0

Views: 84

Answers (1)

Snicolas
Snicolas

Reputation: 38168

You should give it a style, define the style in res/values/styles.xml, then make a different version of the style in res/values-xhdpi/styles.xml.

Upvotes: 3

Related Questions