Can't support multiple screen sizes Android - android

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.

Related

Android layout qualifiers

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.

values-sw resource issue in Android

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

How I should name the layout for 1920x1080 pixels and 5,5 inches device?

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

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

Creating a new sw<xxx>dp qualifier

I have the qualifiers for 7 inch tablets and 10 inch tablets, sw600dp and sw720dp respectively. I don't understand how those numbers were reached.
I would like to create a new layout for phones which a smaller screen size than 4 inches. Please could you explain how I should do this using the smallest width qualifier.
Please checkout "Configuration example" section of official documentation first. It explains very well what is used and when. In your case default layout folder without a qualifier is used for handsets.
What is smallest width qualifier? Smallest width is
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).
For instance your have a phone with screen size equals to 480x800 dp. The smallest width for this device will be the smallest value of these two, which is 480dp. If you rotate your device, the smallest value will stay unchanged - 480dp.
How to use smallest width qualifier? When you create a layout you always expect a minimum width, with witch it swill looks good. Below this minimum your layout gets squeezed and doesn't look good. To make sure this doesn't happen to it, you put it to the folder with sw<N>dp qualifier, when N the minimal allowed width.
It's worth to mention that because smallest width doesn't depend on orientation, you should take case for handling landscape and portrait orientation by yourself by using land or port qualifiers. Although this approach works, it can become complicated to handle different widths and orientations very soon. To address this issue, there is another approach called responsive mobile design. I suggest to read a series of articles "Deep dive into responsive mobile design" to get better understanding.
Update:
The formula for calculating dp from px is like following:
dp = px / (ppi / 160dp)
Nexus 7 takes sw-600dp, because all calculations are based on getResources().getDisplayMetrics().density value coded in the device. This is not the real value, but a rounded value. For Nexus 7 (2013) the real value is 323/160 = 2.01875. The value coded in the device is 2, which corresponds sw-600dp. This is where some pixels get lost.
sw600dp means smallest screen width of density 600dp. But let me tell you that you need more than this because Nexus 7 (2012) and Nexus 7 (2013) are both 7inch tablets but with different densities. You can add hdpi or xhdpi with sw600dp like values-sw600dp-hdpi. For phones do the same swXXXdp but try not to do that and use screen-size like small, normal, large, and xlarge.
For reference see Android official link

Categories

Resources