Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Resource Qualifiers -sw#dp vs -w#dp

Say I'm developing a different layout for devices with screen size equal to or greater than 600dp. I want to use the post android 3.2 resource qualifiers. I created a folder named layout-sw600dp and put my layout there, but at the same time I could have created a folder named layout-w600dp and put the layout xml file there. I'm trying to figure out what is the difference between -sw600dp and -w600dp? After all they are both meant to use the layout for device of width >= 600dp.

like image 732
user1409534 Avatar asked Jul 04 '14 18:07

user1409534


People also ask

What is resource qualifier in Android?

You can use this qualifier to ensure that your app has at least <N> dps of width available for its UI. For example, if your layout requires that its smallest dimension of screen area be at least 600 dp at all times, then you can use this qualifier to create the layout resources, res/layout-sw600dp/ .

What is externalizing resources in Android?

Externalizing your resources also allows you to provide alternative resources that support specific device configurations such as different languages or screen sizes, which becomes increasingly important as more Android-powered devices become available with different configurations.

What is Android res folder?

The res/values folder is used to store the values for the resources that are used in many Android projects to include features of color, styles, dimensions etc.


1 Answers

sw is "smallest width". It doesn't change if the device is rotated.

w, on the other hand, is available (i.e. current) width.

See Providing Alternative Resources:

smallestWidth - sw<N>dp - The smallestWidth is a fixed screen size characteristic of the device; the device's smallestWidth does not change when the screen's orientation changes.

Available width - w<N>dp - This configuration value will change when the orientation changes between landscape and portrait to match the current actual width.

Example. Say that you have a device that is 600dp x 400dp.

  • If you have a w600dp resource, it will be used in landscape, but not in portrait.
  • If you have a sw600dp resource, it will not be used for any orientation (smallest is 400).
like image 73
matiash Avatar answered Sep 20 '22 16:09

matiash