Rashid Al Shafee
Rashid Al Shafee

Reputation: 73

Dimen value confusion in Android

I have the requirement like this

For Width: sw0-320: 100dp,

sw321- : 200dp

Where should i put this values?

In values folder: 100dp or 200dp,

In values-w320dp folder: 100dp or 200dp,

Confused here! Studied some doc but didn’t understand the fact here!

Upvotes: 0

Views: 300

Answers (2)

Bea
Bea

Reputation: 158

The data in the values-sw320dp or values-w320dp folders will be used if the device has a smallest width or available width of 320dp or more, otherwise the data in the values folder will be used. So, in this case you need to put 100dp in the values folder and 200dp in values-sw320dp or values-w320dp. The question says the requirement is about sw (smallest width) but then it uses the available width (w) qualifier in the folder name, so it's not clear which one you'll need.

The documentation for this is in https://developer.android.com/guide/topics/resources/providing-resources and there you can check the smallestWidth (sw<N>dp) and availableWidth (w<N>dp) qualifiers.

Upvotes: 2

Daniel Wilson
Daniel Wilson

Reputation: 19824

Android finds the most specific resource it can for the device it's running on first.

This means if you place something in values-sw320dp and you are running a device with a smallest width of 320dp or more, it will look here first. If it can't find the resource in that folder, it will look in the base values folder. If you are running a device with a smallest width of 319dp, it will not look in values-sw320dp for a resource.

Upvotes: 2

Related Questions