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.
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).
Related
I'm working on a Android App. Layout working fine on every device except where device screen size 480x800 & less.
How can create separate layouts by only targeting that screen size or less?
I'm already tried layout-hdpi, layout-small-hdpi & layout-normal-hdpi since phone like Nexus S, Nexus One are in hdpi category. But when I create separate layouts like layout-hdpi those layouts are affecting phone with bigger screen like Pixel, Pixel2, Nexus 5 etc.
Thanks in Advance
Phones (as opposed to tablets) tend to come in about three size groups (as far as Android resources are concerned): those with smallest width of 320dp, those with 360dp, and those with 410dp. The resources framework gives you a way to target any device larger than a certain width, so the correct technique is to put layouts for small screens on the default folder, and layouts for larger screens in one of the qualified folders.
Since it sounds like your layouts currently work well for anything 360dp or larger, you can make two layout directories:
res/
layout/
layout-sw360dp/
Put the special layouts for the small screens inside res/layout/ and put the “normal” layouts in the other directory.
Its not easy but you can also specify layouts based on the smallest width and you you supply the numbers. You can get more detailed and separate layouts that way however in my experience you will still run into that problem from time to time. In my current project using this method I have specific folders for W360 and W400 to deal with smaller devices for one specific screen.
https://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts
What you are looking for, is a layout bucket with the smallest width qualifier.
A layout with a set smallest width will be active, unless the smaller of the both dimensions (width or height) is lower than a certain value you can choose.
So, when a device has a smallest width below some value X it will use the default layout, when the value is X or more it will use the defined smallest width layout.
To create such a layout file in Android Studio, you wanna right-click your layout directory, click on new -> Layout Resource File and select the Smallest Screen Width qualifier from the list of available qualifiers. Now you need to specify your smallest width, which in your case should be slightly above 480dp. Give it the same name as your current layout file. Place your code for devices with a smallest width above 480p here. Now change the code in your other layout file, without the smallest width qualifier, to support smaller screens.
For further reference take a look at the official Android Developer page.
I currently work on an application which has to support different screen sizes. I read through the documentation about this and decided to create different layout with the smallest width qualifier. The documentations notes:
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.
I did so and everything works great but nevertheless I am a bit confused: Due to device metrics the Google Pixel should have a minimum width of 411 dp. In my application I created a layout with the sw480dp qualifier but when I select the Pixel device from the Android Studio layout editor it always opens the normal layout without qualifier.
I also tried to create my own hardware profile for the Galaxy S6 (360 dp) through the AVD manager but it faces the same problem. Have I missunderstood something here?
I also do not quite understand this image from the documentation. How do I have to read it? The small, medium, etc. qualifier are deprecated so why are they in there or is this only used for conversions?
In my application I created a layout with the sw480dp qualifier but when I select the Pixel device from the Android Studio layout editor it always opens the normal layout without qualifier.
411 is less than 480. Hence, -sw480dp is not a valid qualifier.
Have I missunderstood something here?
The NNN value in -swNNNdp is the lower bound, not the upper bound. Devices with a smallest width of NNNdp or larger would use -sw480dp.
How do I have to read it?
I have no idea what information that image is supposed to be conveying.
I have two devices:
Moto-G first generation (720*1280, 4.5" 324.2 PPI)
ICE Tablet (600*1024 7" 169.55 PPI)
And created folders "values-sw420dp-xhdpi" and "values-xhdpi" for Moto-G and folder "values-sw360dp-mdpi" for ICE Tablet. But both devices taking the values from "values-sw360dp-mdpi" folder.
I am very confuse about this behavior of the devices because both are quite different, however why this is happening ?
Can anybody please guide me how to define sw folder for these two devices and in general how sw is working? I read the official guide line of sw folder and supporting multiple screens, but did not got exact idea.
According to your question, let me cite a fragment from Android Developers Guide:
Screen configuration: smallestWidth
Qualifier values: swdp
Examples: sw600dp sw720dp
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 <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/. The
system will use these resources only when the smallest dimension of
available screen is at least 600dp, regardless of whether the 600dp
side is the user-perceived height or width. The smallestWidth is a
fixed screen size characteristic of the device; the device's
smallestWidth does not change when the screen's orientation
changes.
Full Text: Supporting Multiple Screens
Like #tiny said:
sw420dp-xhdpi means screenWidth = 840(420 *2) ,
sw360dp-mdpi means screenWidth = 360(360*1)
EDIT: Using this site http://pixeldensitycalculator.com/ I've already calcualated that
Moto G 1st edition has density 293.72 ~ 320dpi
ICE Tablet has density 169.55 ~ 160dpi
None of these devices doesn't have more than 320dpi, that's why none of them using your 420dpi folder.
Hope it help
I want to create a special layout for a device with 1920x1080 pixel and with 5,5 inches.
Does anyone know how I have to name my layout for this?
Now I have for example for the Nexus 10 a layout named layout-sw720dp
I found anytime a calculator for this, but I cant find it anymore.
thx.
So first you need to understand what's the meaning behind layout-sw720dp
Based on Android Documentation on Supporting Multiple Screen sw mean smallestWidth and the format is layout-swdp.
so 720 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 its UI.
For example, if your layout requires that its smallest dimension of screen area be at least 720 dp at all times, then you can use this qualifer to create the layout resources, res/layout-sw720dp/. The system will use these resources only when the smallest dimension of available screen is at least 720dp, regardless of whether the 720dp side is the user-perceived height or width. The smallestWidth is a fixed screen size characteristic of the device; the device's smallestWidth does not change when the screen's orientation changes
I need some help with design for multiple screen sizes in Android.
I created layout, layout-sw600dp, values, and values-sw600dp with dimens.xml file with dimension for layout-sw600dp.
But when I run application in emulator with 7" tablet, the design is not set up properly.
How I can fix this?
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 has at least dps of width available for its UI. the device's smallestWidth does not change when the screen's orientation changes.
Try to use layout-w600dp instead of sw.