How to test android app on all screen sizes - android

I've created my app but I decided to test it on all screens to be adaptive. Maybe testing it in
MDPI(160dpi), HDPI(240dpi), XHDPI(320dpi), XXHDPI(480dpi) and XXXHDPI(640dpi) which corresponds to all screen sizes. However I tested my app on two devices support 320dpi. I thought that I get the same result but it don't. so don't know how to test my app on all screens. I'm confused.
I used Genymotion for emulators:
one with 720 * 1280 320dpi
screenshot
and other with 1200 * 1920 320dpiscreenshot
Please help me with that or if there's another way to do it let me know.
thanks in advance

(Bunch of explanation about why this is happening, I put my suggestions in the last section)
DPI isn't the same as size, it's just about how many pixels are packed into a certain area. The higher the DPI, the more pixels there are, meaning they're a lot smaller. So you can get fine detail, but it also means you need more of them to cover a physical distance or area on the screen.
Which is why Android uses dp instead of raw pixel sizes most of the time - the standard minimum touch-target size is 48dp, but how many actual pixels that is depends on the pixel density of the display. For mdpi displays it'll actually be 48 pixels, for xxxhdpi it'll be 4x that amount
It also means if you're doing your design work in dp, the pixel density of the screen doesn't matter - elements with a fixed size will always be broadly the same size on every screen (the mdpi etc buckets are like a "close enough" grouping, the devices in each group won't all have exactly the same DPI) because it's getting translated to the equivalent number of actual pixels. What testing does help with is checking your drawable assets look ok on different screen densities
So you have two devices with the same DPI right?
720 x 1280
1200 x 1920
Because they're the same DPI, those dimensions are converted to dp by the same factor. Let's work it out to be precise (but the exact numbers aren't important): 320 DPI is xhdpi according to that link up there, so 1dp = 2px. Let's convert those screen sizes to dp
360dp x 640dp
600dp x 960dp
It's the same situation but hopefully having those sizes expressed in dp helps you see the problem - when you're designing a layout, you're working with dp, right? The available space you have to work with is defined in dp, and one of those has a whole lot more space than the other! Putting a 300 dp-wide TextView in the layout would almost fill the first one horizontally, but it would only cover half of the second. That's gonna look pretty different!
This is why phones and tablets look so different - even if you have a relatively new phone, and an old Nexus 7 with a much lower resolution, the Nexus 7's screen is going to feel "bigger" and more "spacious". It's a physically larger device, so even though it's low-res, it's also low-density which means those pixels are spread across a larger area. Lower DPI means those pixels translate into more inches. And in the density-independent pixel (dp) system, that means you get way more dp to work with, more space for your layout. Which is what you want on a tablet, you don't want it to look and feel like a massive phone!
That's why it's different - basically one of your devices has more space to work with than the other, because it has more pixels, and the same DPI so those pixels aren't just used for finer detail.
As for testing, you need to look at different screen sizes - which is dependent on the resolution and the DPI. Basically pixels / DPI = size in inches. Do that for your two 320 DPI examples and you'll see one is a fair bit larger, physically, while having the same density
Probably the easiest way to do this, really, is to look at your layout in the design view, and change the Preview Device setting at the top. Some of the Phone devices are more "spacious" than others, newer ones are taller, so go through them and see how your layout changes. Try a Tablet one and see what a lot of extra space does. And if you go down to the Generic Phones and Tablets section at the bottom, there are a bunch of reference devices in there, some of which will be very cramped!
Once you've found a few useful ones, you can set up your emulator / virtual devices with each of their screen resolution / density combinations. I don't know about Genymotion, but the built-in AVD manager gives you a lot of those device definitions as templates when you create a new virtual device. You should at least be able to enter those settings yourself
Also when you publish an app on the Play Store, they'll automatically run it on a bunch of reference devices and give you access to a bunch of screenshots, so you can see if there are any problems with certain screen sizes and fix them before you launch

Related

How do I translate the sizings of a Lenovo Tab M8 into pixels for Figma?

My company has a Android app. Our clients view the app with a Lenovo Tab M8. I am a designer tasked with recreating the current app experience in Figma so that our design team can have a design system and make accurate mockups. But I'm struggling to capture basic measurements (my experience is in Web and not Native apps).
The first question is, what is the width and length of the screen in pixels? I'm trying to create a basic screen template in Figma. I know the Lenovo display is 1280x800px with 16:10 screen ratio. But when I create a 1280x800 frame in Figma it's significantly larger than the physical device. I'm a little lost.
The other question is, I'm trying to recreate font sizes but I know the app uses dp and not px. I found a site that convert them, but I don't know if the tablet is LDPI, MDPI, or whatever.
https://www.pixplicity.com/dp-px-converter
Thanks for any insights you have.
You shouldn't need to know what density the tablet is, the point of using dp (density-independent pixels) is that everything will look pretty much the same size in the real world. The baseline density is LDPI, which is 160 pixels per inch - so 160dp is one inch on the screen.
XHDPI is 320 pixels per inch, so double the density - but converting 160dp to pixels on XHDPI devices involves multiplying it by 2, so the result is 320 pixels - which again corresponds to 1 inch on a 320dpi screen. See how it works?
So the pixel resolution isn't important, a tablet will be large in dp terms because they're physically bigger than a phone, more inches and all that. But if you're curious, if your M8 is the 2nd-gen one, according to the tech specs it's 4.8" on the 800 px axis (the one with the smallest bezels), and that works out to 166.7 DPI without taking those bezels into account - so it's an LDPI device!
I don't know anything about Figma, but so long as you're using dp measurements it should work ok? You have to be aware of the size of your screen though - when you said you created a frame 800 high and it was too big, if that was 800dp then 800 / 160 is 5" and your screen is only 4.8" high. Ideally your layout shouldn't require a specific physical size though, it should be able to adjust since different devices (even very similar ones) are different sizes - but I don't know how Figma works with that! That's just the way it works for the standard Android stuff
Also ideally fonts should use sp which is like dp but it has an additional scaling step depending on the user's font size settings on the device - it lets them shrink or enlarge text to their preference and for accessibility (the latter is especially important). Sometimes you want a fixed size for something that's more of a graphic element, but generally text should be scalable
If you want to know how to convert, have a look at the Material Type System - there's a chart there for converting between different units (also 1sp = 1dp for the Normal text size FYI). There's also a tool on there to create a type scale but only for stuff on Google Fonts - just saves you doing it yourself!

Android DisplayMetrics inconsistent between devices

I'm trying to use DPI and touch input in my unity game to recognise gestures consistently across android devices of different sizes.
For instance, I want my virtual thumbstick to be two inches from "full left" to "full right". Given the DPI of the screen, I can convert touches from pixels to inches like this: inchesFromStickCenter = pixelsFromStickCenter/dpi.
To get DPI, unity offers Screen.dpi but I was getting inconsistent results across devices. Sometimes the thumbstick was way too big, sometimes way too small. Instead I went straight to Android's DisplayMetrics, where I could get xdpi, ydpi, and densityDpi. From this question Difference between the declared size in inches and the size obtained using DisplayMetrics I see that densityDpi is a rounded value, and I should probably be using xdpi or ydpi.
I tested things by trying to compute the width of the screen in inches (my is landscape, all these examples assume landscape). When I divide the screen pixel width (1280) by xdpi (195.4) on my 1st gen N7, it overestimates the screen width by half an inch (6.55 inches, compared to just under 6 when measured with a rule). When I divide by densityDpi (213), it's a much better answer. The wikipedia page for the N7 says dpi is 215, which would also give a great answer.
When I test on my Galaxy S2, the xdpi (217) gives a good screen size estimate, and the densityDpi (240) gives an underestimate by a third of an inch.
So I can't depend on either of these numbers! Why is neither N7 stat nothing like the wikipedia page? Is this a silly way of trying to convert pixels to real-world inches? What should I be doing instead?
Cheers!

Supporting Multiple Screens in Android

I have developed an android app and its working fine in my mobile of resolution 240*320.But if I install in another mobile some like 240*400,480*800, etc all the view components are changing according to the screen resolution.
I also created a sub folders under the res like layout-small,layout-large,layout-xlarge this procedure is also working according to the screen resolution the xml files are been read by particular folder.But this is not working on a 240*400,240*432,etc.., these type of screen resolutions are not supporting by the above procedure
What should i do for achieving all the view components to be look same for all screen sizes.
Thank you
This stuff is hard. You may have read the documentation, but you haven't understood it.
Basically, you have to distinguish two important things.
Layouts (XML) are determined by the dp size of the device. Forget about 'resolution' and just think about device independent pixels (dp). The dp size of a device is roughly equal to its size in inches, if it had 160 dots per inch. So a 10" tablet is about 8"x160=1280 dp long, while a 4" phone is about 3"x160=480 dp long. Approximately.
Drawables (PNG and JPG) are determined by the pixel resolution of the device. To produce the identical icon on a device that is 320 dpi and for one that is 160 dpi you need twice as many pixels. A 64x64 icon on the first is only 32x32 on the second.
So you need to produce a range of XML files (layout or dimen) that scale according to the desired dp size and put them in folders with names like sw600dp (shortest width 600 dp) and sw320dp. (Search SO or the web for sw600dp and you'll find lots to read).
And you need to produce a range of PNG or JPG files that scale according to the pixel resolution and put them in folders with names like mdpi and hdpi (search for that too).
Simple enough, but hard to do well in practice. We can only hope that eventually Android will fix this mess but for now this is what we have.
First off, stop using the term resolution. That term is ambiguous.
In Android, one could easily have a phone with a small screen with very high pixel density and a large tablet screen with very low pixel density, and the so-called resulting resolution on both devices could still end up being equal.
i have read that many times and implemented according to that but read
my question properly. – user3851899 3 hours ago
I'm sorry, but believe us, we've parsed your question very thoroughly.
http://developer.android.com/guide/practices/screens_support.html
You've mentioned the term "resolution" five times and yet in the document you've read many times, below is the only part where resolution is even mentioned, and even then, it's to tell us that you should "not directly work with resolution".
Resolution
The total number of physical pixels on a screen. When adding support for multiple screens, applications do not work
directly with resolution; applications should be concerned only with
screen size and density, as specified by the generalized size and
density groups.
Furthermore, can you count the term density is mentioned in that document. It's mentioned 171 times! The fact is, you've missed the main key take away concept from that document.
The term resolution is not very useful for Android development. The concept of size is important for a large background image taking the entire width or the entire height of the screen and it's important for layout issues that take into account the entire height of the screen or the entire width of the screen, but it's not very important otherwise. And what's really important for developing on multiple screens (aside from the scaling font size) is really the density of the screen.
So I implore you, please read that document again. Hopefully, you'll begin to understand it, now that I've reset some of your assumptions.

Android: how to calculate dpi from a design?

I have a 800 x 480 (landscape) design made in photoshop and now I'm trying to implement the same design on Android.
How am I supposed to calculate width and height for a LinearLayout? For example, a header has 800px width and 60px height. How many DPI they are?
The min and the target SDK are 14. Am I need to worry for devices that are using a smaller display? (Smaller than 480x800) ? (I don't know if older devices can run Android 4+)
I have tested on my AVD (Nexus 7) and this is how it's look (accordingly to my photoshop design):
But on a tablet:
Am I need to create different layouts for different devices?
First thing that you need to understand - for which density your design is. Most common situation is design in mdpi, which means that 1dp on device (with mdpi screen) will be equivalent to 1px of design layout. On devices with higher density it will be increased accordingly (4:6:8 rule).
Second thing - providing values in dp won't magically scale up your layout for larger devices. Note, that dpi is not the same as screen resolution. So, for example, large 10inch tablet with 1280x800 screen resolution is mdpi device (not hdpi, not xhdpi).
Third. It makes no sense to say "800x600 device is smaller that 1280x800", because they may both be, for example, 4inch phone.
Fourth. Screen resolution have nothing to do with SDK version.
What you need to do, is look for another design for larger devices or ask designer about what he wanted to see. Maybe images shouldn't be strictly sized in dp, maybe they should be sized in percentage of the occupied screen?

Screen resolution / Physical size

I'm implementing an app for Android(API 10). I have few designs for tablet(supposedly) and for mobile phone. Regarding the previous sentence it might sound a bit stupid: in my opinion layouts should be picked according to device's physical size - not resolution, otherwise there might be a phone with high resolution that renders, say, a grid of 5x5, in rather confusing, inadequately small-sized way. In order to provide division by physical size I gotta use /res/layout-* folders. Agreed ?
Also: I'm a bit confused about multiple-screens guide's definition on physical size. Would you mind explaining what physical size is in terms of Android mean, what it's measured in? Is there any correlation with dpi?
Thanks.
A workaround for api level 10 could be something like this:
use the compat lib from the SDK so that you can design with fragments.
Assume everything before android 3 is a phone. For example use your layout files in layout/* for this (and the rest will be based it on unless overriden). This assumption is basically only wrong for the original Samsung Galaxy Tab 7" from 2009.
Assume everything on android 3.x is a tablet (they are), so do some tablet specific layout if you want and have them under layout-v11 (and maybe also layout-v12 if there is anything specific to android 3.1). Tablet specific layout could mean that you arrange your fragments differently and/or show multiple fragments at the same time.
Everything newer (android 3.2+) you can use the new stuff from api level 13. Such as layout-sw600dp/ for some layouts etc etc. http://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts
Physical size is usually measured in inches, it simply tells you the real device's screen size (usually 3-4" inches for phones and 8-11" for tablets).
dpi, is NOT correlated with it. Dpi expresses screen density, how many pixels are shown in a given area (usually a square inch). It could be considered as a measure of screen quality.
Resolution is given by the product of the two; it expresses the total number of physical pixels on a screen.
Going back to your first question, you should be density independent as much as possible; your app should "look the same" on devices with different densities. The /res/layout-* folders are designed to provide this feature, the system scales drawable resources to the appropriate size and you could then declare in your manifest that your app supports any density:
android:anyDensity="true"
On page http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch you can learn how Android choose the best matching resource.
With Android API 10 the best option for targeting tablets is probably just distinguishing the actual size of the screen in the code using something like:
https://stackoverflow.com/a/5789916/1319155
and then just load a different drawable if the size value returned was greater than 6 (or whatever size you want to declare as a "tablet").
The reason you can't really just use the size folders (i.e. layout/large) is because the folders don't distinguish between phones and tablets very well. A kindle fire and galaxy nexus may both be considered "large" devices.
The reason you can't really use dpi is because that is not a good reflection on what type of device it is, just how "dense" the pixels are on a screen. Most new phones are much denser (having more pixels per inch) than tablets anyway.
There are two ways of doing this. From Android 1.6 (API 4) on, there are four layouts that describe the physical size of the display: small, normal, large, and xlarge. As described on http://developer.android.com/guide/practices/screens_support.html , these correspond to:
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
Note that these are measured in DP, not DPI. DPI is Dots Per Inch, and specifies screen density. DP, also written DIP, are Density-Independent Pixels. Again from the guide:
Density-independent pixel (dp)
A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
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. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
In other words, 160 DP = 1". Applying this standard, we see:
xlarge screens are at least 6" x 4.5" (7.5" diagonal)
large screens are at least 4" x 3" (5" diagonal)
normal screens are at least 2.9" x 2" (3.5" diagonal)
small screens are at least 2.6" x 2" (3.3" diagonal)
(Not sure why the selection is so odd, but that's what they defined.)
From Android 3.2 on (API 13), there are more options, as described here:
http://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts
Here you can use "smallest screen width," "available width," or "available height" options to define your own categories; again, the unit in question is DP, which is 1/160". Note that these specify the smaller of the two dimensions on the device--e.g., for a 7" tablet they recommend specifying layout-sw600dp, that is, "smallest width 3.75 inches," which would be intermediate between the "large" and "xlarge" sizes defined in API 4. They have a number of specific comments about this topic, including notes about how the widths are measured (it may exclude things like the notification bar), so it's worth taking a look at the documentation.

Categories

Resources