Difference between sw600dp and w600dp?

AndroidLayout

Android Problem Overview


Please elaborate on the difference between sw<N>dp and w<N>dp, in a simple way. I have studied the complete documentation of screen sizes but am confused between these two qualifiers sw<> and w<>.

Android Solutions


Solution 1 - Android

Android device screens are rectangles. Rectangles have two sides, one shorter than the other. Let's call the short one A and the long one B.

-swNNNdp indicates "use these resources if A is greater than or equal to NNN dp in length"

-wNNNdp indicates "use these resources if the width of the device, as presently held, is greater than or equal to NNN dp"

When the user rotates the device between portrait and landscape, the width will change (to be A or B), but A (the shortest width) is always the same.

Solution 2 - Android

Please take a look at Screen Support

According to the documentations :

SW : The fundamental size of a screen, as indicated by the shortest dimension of the available screen area. Specifically, the device's smallestWidth is the shortest of the screen's available height and width (you may also think of it as the "smallest possible width" for the screen). You can use this qualifier to ensure that, regardless of the screen's current orientation, your application's has at least dps of width available for it UI.

while W : Specifies a minimum available width in dp units at which the resources should be used—defined by the value. The system's corresponding value for the width changes when the screen's orientation switches between landscape and portrait to reflect the current actual width that's available for your UI.

In my words :

SW : minimum distance between screen edges in dps your layout will run on, so if you use layout-sw600dp/ folder then all layouts inside it will only work on devices that has at least 600dp (width or height)

W : means your layout will work on any device with n dp width regardless of the height or maybe the device currently in landscape mode (in this case w would refer to the height .. since orientation differs between landscape and portrait)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMudassar ShaheenView Question on Stackoverflow
Solution 1 - AndroidCommonsWareView Answer on Stackoverflow
Solution 2 - AndroidMr.MeView Answer on Stackoverflow