Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Provide a resource if width is smaller than specific DP

How do I use the resource qualifiers system in Android to specify that I want a resource to apply only if the width is smaller than a particular value?

To elaborate, suppose I want to provide one layout whenever the current available width is up to - say 320dp - and another layout for all other cases. This is what comes to mind:

layout-w320dp/mylayout.xml
layout/mylayout.xml

However, as per my understanding of the resource matching algorithm, even a large device (say, a tablet in landscape) qualifies as w320dp - because, well, the available width would be greater than 320dp.

As such, the resource from layout-w320dp would always be picked - even for larger phones and tablets. The only time the default resource from the layout folder is picked is if the available width is less than 320dp.

So, how do I express a "smaller than" relationship using the Android resource matching system?

like image 924
curioustechizen Avatar asked Dec 12 '13 13:12

curioustechizen


1 Answers

Ugh! Just after posting the question I realized that one way to do this would be to negate the equation - i.e.:

layout-w320dp/mylayout.xml --> layout for screens larger than 320dp
layout/mylayout.xml  --> layout for up to 320dp

However, I'm still interested in knowing if the original "smaller than" relation can be achieved since it makes the intent much clearer.

like image 158
curioustechizen Avatar answered Sep 30 '22 17:09

curioustechizen