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?
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.
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