Android tablet emulator 10 inch 320dpi does not load layout-sw720dp - android

This is probably an easy question, but i am just overlooking something.
I have an Android emulator with the following specs:
In my app I provide different layouts:
res\layout
res\layout-sw600dp
res\layout-sw720dp
But this emulator loads the regular layout.
I have another emulator with 160dpi and the rest of the specs are the same.
This one does load the sw720dp layouts.
Why doesn't the 10 inch 320dpi emulator loads the sw720dp layout?

From http://developer.android.com/guide/practices/screens_support.html
px = dp * (dpi / 160)
dp = px / (dpi /160)
With 1280x800 320dpi, sw = 800, than you get:
dp = 800 / (320 / 160) = 400dp
That is why it does not load res/layout-sw720dp or 600dp.
Solution would be to make sw400dp resources.

Related

How to determine smallest width of android device

I am new to the concepts of android layouts associated with different screen sizes. I wish to make a different layout for a tab which is of 8" and place it in a "layout-swxxxx" folder. And have another generic layout for tabs bigger than than 8" in "layout" folder.
Here is the configuration of my 8" tablet.
Screen size 8.0 inches
Resolution 1200 x 1920 pixels (~283 ppi pixel density)
Can anyone tell me how to calculate the "sw", so that i can name my layout folder accordingly.
Also I don't have the physical device with me so its not possible for me to find this value with any code. So request an alternative method.
Thank you in advance.
The formula linking dp, pixels and density is as follow :
px = dp * (dpi / 160)
Therefore, in your case,
widthInDp = widthInPx / (dpi / 160)
widthInDp = 1200 / (283 / 160)
widthInDp = ~678dp
So you're gonna want to use a bucket such as sw600dp
Reference : http://developer.android.com/guide/practices/screens_support.html

Android alternatives resources for 5.5'' and 6'' phones

I would like to know how can I add alternative resource for android devices with 5.5'' and 6' within a project structure.
I want to add a custom dimens.xml file with different text sizes for devices between 5.5 and 6 inches.
I was thinking to use the small width configuration qualifiers but there is so many screen configuration that I do not know which screen size would be the smallest width for 5.5'' and 6'' phones. The other alternative that I can use is the screen size buckets (small, normal, large, xlager) but those are deprecative from android 3.2 and above.
Can someone advice me about this?.
I appreciate your advice, but look this example.
I have this phone:
- Nexus 5x with 5.2’’ resolution 1080x1920 px, 420dpi
dp = px / (dpi / 160)
dp = 1080 px / (420 dpi / 160)
dp = 411 dp
Nexus 6p with 5.7 resolution 1440x2560 px, 560dpi
dp = px / (dpi / 160)
dp = 1440 px / (560 dpi / 160)
dp = 411 dp
if I create a specific set of resources just for the Nexus 6p with 5.7’’, or for devices with just 5.7’’ I could crate this folder
values-sw411dp
But all the resources within that folder will be used when the app is used on both devices 5.2’’ and 5.7’’.
I have other problem, it may be that smallest phones like, 5.0’’ could have biggest dp than the 5.7’’, what its going to happen is that the resources for the 5.7’’ device it will be used for the 5.0’’ devices too.
How can I specify resource just for 5.7’’ phones.
Well, you are right I'd also go with the smallest-width buckets.
You can calculate the smallest width, by checking the phones dimensions in dp, with the formula given in the official documentation:
px = dp * (dpi / 160)
So to get the smallest width dp:
dp = px / (dpi / 160)
Where px is the pixels on the smaller dimension, dpi is the dot per inch ratio of the device.
So first check the devices' pixel size and dpi value, then calculate the dp value with the formula above. Then you can create the folder with the resources like sw400dp where you can change to the calculated dp.
Also I'd suggest to check for other device dimensions to not have weird layouts on smaller / larger screens.
Abbath, thank you very mucho keep answering my questions. I am not working with images, I am working with the text size of a TextView. I need to change the textView text size, only if the devices screen size is bigger than 5.5''. I created a /value-sw411dp/dimens.xml which contain the corresponding textview text size. I found that sw411dp is the smallest dp width of the 5.5'' devices, but there is an other phone that has 5.2'' that has the same screen spaces. So, the system will used the resources within the /values-sw411dp/ for devices with 5.5''and 5.2''.
What you where telling me is that if a 5.2'' has the same screen dp as a 5.5'', I shouldn't worried about that because at the end the UI layout will look the same without problems.

Conversion from px to dp for Google nexus 7

I am new to tablet application development. I am having Google Nexus7 with screen resolution (600 * 960 dip) So I want to know is it fall in to mdip category?
According to that 1px = 1dp (baseline). But If I follow this its not looks good on tablet. I am creating separate layout folder for nexus7 -sw600dp and mention sizes according to mdip but it not working. My images also not looking good. What I want to know what is actual conversion rate for google nexus 7. Need help.
Formula: pixels = dips * (density / 160)
The Nexus 7 is 800x1280 with a 213 px density, which means it's resolution code is tvdpi (which means you can have a folder called drawable-tvdpi).
You can measure available screen size, minus window decorations, with:
this.getResources().getConfiguration().screenWidthDp;
this.getResources().getConfiguration().screenHeightDp;
On my N7, it returns 600 dp w, 888 dp h. Following the above formula, 888 dp height is 1280px - window decoration.
The Nexus7 is a unique device, with a somewhat strange dpi structure.
For nexus 7
layout-large-hdpi
Here is a very good explanation (from Dianne Hackborn - an Android engineer at Google): Dianne Hackborn explains the unique resolution of the Nexus7
Note: The app takes images from these folders only if you have not given higher precedence qualifiers. For example if you have given a layout folder like layout-sw360dp the app will take only the images from this folder even if you have given separate layouts like the one I said above. Because in android there is an order of precedence in which you have to give layouts.
Screen Density
Commonly referred to as dpi (dots per inch). Android groups all actual screen densities into four generalized densities: low (120), medium (160), high (240), and extra high (320). A device such as Galaxy Nexus has "extra high" screen density (more specifically, the dpi value is set at 320). The Nexus 7 uses "tvdpi" - i.e. 213 dpi.
Density Independent Pixel
Commonly referred to as dp. This is the virtual pixel unit used when displaying content. The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen. To calculate dp use the following formula:
px = dp * (dpi / 160)
or equivalently:
dp = (px / dpi) * 160
The reason Nexus 7 can show more content than the Galaxy Nexus despite having similar resolutions is this: the dpi of Nexus 7 is lower than Galaxy Nexus.
Galaxy Nexus (320 dpi, 720 pixels wide)
(720 / 320) * 160 = 360 dp
Nexus 7 (213 dpi, 800 pixels wide)
(800 / 213) * 160 = 600 dp
This means that when apps are rendering on the Galaxy Nexus, the width of the screen is actually 360 dp (rendered using 720 pixels). Whereas on the Nexus 7, the width of the screen is 600 dp (rendered using 800 pixels).
Try below code, give pixel value to below method it will give you result in dp.
public int convertSizeToDeviceDependent(int value) {
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
return ((dm.densityDpi * value) / 160);
}

Galaxy tab 2 7" does not fit sw600dp?

Everywhere in Android documentation I can ready that I have to use sw600dp for 7 inch tablets, but this does not seem to be true, because Galaxy Tab 2 7" has 546dp for its smallest width.
http://www.gsmarena.com/samsung_galaxy_tab_2_7_0_p3100-4543.php
dp = 600 / (170 / 160) = 546
Should I use sw500dp in my layouts instead?
Android device pixel densities are classified in buckets:
While the Galaxy Tab 2 screen may actually be 170 dpi, that falls within the range of mdpi which translates to 160 dpi being used in practice for dp calculations. The device should still have a 600dp width.

Trying to define which layout should a device use

I'm trying to understand which layout uses which device.
For instance, I've different layouts:
layout
layout-sw600dp
layout-sw720dp
Nexus 7" (800x1280) uses layout-sw600dp
Samsung GTp3100 7" (600x1.024) uses layout-sw600dp
Samsung Tab 10.1 (1280x800) uses layout-sw720dp
Sony XPERIA S 4.3 (1280x720) uses layout
Can you guys explain "with your words" why isn't XPERIA S using sw600dp or sw720dp?
SW != smallest width? So smallest with from XPERIA S is 720. It should be using sw720 or sw600, right? Or am I wrong?
I've read tons of documentation, but can't understand why is this happening.
Thanks a lot.
The Smallest-Width qualifier refers primarily to screen size and not the physical pixels.
Using sw720dp for example means the device must have a minimum screen width of 720 dp (device-independent pixels) - this isn't about 720 physical pixels. From the documentation...
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen.
The physical width of the Sony XPERIA S 4.3 is 2.5" but I don't know how much of that is the actual width of the screen.
Let us pretend for the sake of calculations that the screen covers the full width...in this case to calculate dpi for width we simply use 720 / 2.5 = 288dpi.
From the documentation for dp...
The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160).
Rearranging the formula above to calculate dp we do this...
dp = px / (dpi / 160)
...this gives us the width in dp (and a necessary Smallest-width qualifier) of...
720 / (288 / 160) = 400dp
In short the answer is, the Sony XPERIA S 4.3 may have a high-density screen (for its size) but it isn't a large screen.

Categories

Resources