How to design for Android Multiple Screens? - android

1st Image: Default Normal Screen
2nd Image: Galaxy Nexus 4.65" (Eventhough it looks larger, it is under normal screen)
3rd Image: Large Screen
how to design for particular screen size? I mean both 1st and 2nd image comes under 'normal screen'. Suppose If I create new layout folder for Galaxy Nexus (4.65",720x1280) and i was working on it, it affects default layout folder.

if above solution does not work.try this ,it will surely work ,i have tested this. if you want your app work on different different version of OS.
Use these three layout's.
For
tablet>3.2 and up verion
1-layout-sw600dp
For
tablet<3.2 and lower version
1-layout-xlarge
For
Smart phone
1-layout

Here's my general guide on how to design for different screens:
https://stackoverflow.com/a/12739568/1369222
If you are looking to target only the samsung galaxy nexus, see here:
https://stackoverflow.com/a/9212675/1369222

use this link http://developer.android.com/training/multiscreen/screendensities.html
here they provide drawable (if you want to use image) for each screen with the same image ,your device automatically choose their own pic according to their density.
res/
drawable-xhdpi/
awesomeimage.png
drawable-hdpi/
awesomeimage.png
drawable-mdpi/
awesomeimage.png
drawable-ldpi/
awesomeimage.png
and this is for layout ,make new folder in your res folder and give name it layout-large and put same xml file in this i.e main.xml.
res/
layout/
main.xml
layout-large/
main.xml

Here you go if your looking for something like this, idk, im trying to get some votes im kicked off questions and im stuck, gota get back on this thing
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
Generalised Dpi values for screens:
ldpi Resources for low-density (ldpi) screens (~120dpi)
mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).
Therefore generalised size of your resources (assuming they are full screen):
ldpi
Vertical = 426 * 120 / 160 = 319.5px
Horizontal = 320 * 120 / 160 = 240px
mdpi
Vertical = 470 * 160 / 160 = 470px
Horizontal = 320 * 160 / 160 = 320px
hdpi
Vertical = 640 * 240 / 160 = 960px
Horizontal = 480 * 240 / 160 = 720px
xhdpi
Vertical = 960 * 320 / 160 = 1920px
Horizontal = 720 * 320 / 160 = 1440px
px = dp*dpi/160

Related

Multiple screen support based on screen size

I am developing an android app that run on every size screen. For this I have created folder drawable, drawable-ldpi, drawable-mdpi, drawable-hdpi and drawable-xhdpi. And for layouts creating folders layout, layout-small, layout-normal, layout-large and layout-xlarge. For values I am creating values, values-small, values-normal, values-large, values-xlarge. This is first time I am working on multiple screen support. And on Internet so many links that explain multiple screen support in different ways. So I have few questions.
There is need of any other folder than these folders?
Am I doing right?
How to convert resolution from ppi to dpi?
And the important thing I am creating app only in portrait mode.
Edit-
First I am creating values folders with ldpi, mdpi, hdpi. But devices belongs to same dpi but having different sizes creating problem. So I decide to create folders like above.
Dp are Density independant pixels and are used to generalise the number of pixels a screen has. These are generalised figures taken from
http://developer.android.com/guide/practices/screens_support.html
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
Generalised Dpi values for screens:
ldpi Resources for low-density (ldpi) screens (~120dpi)
mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).
Therefore generalised size of your resources (assuming they are full screen):
ldpi
Vertical = 426 * 120 / 160 = 319.5px
Horizontal = 320 * 120 / 160 = 240px
mdpi
Vertical = 470 * 160 / 160 = 470px
Horizontal = 320 * 160 / 160 = 320px
hdpi
Vertical = 640 * 240 / 160 = 960px
Horizontal = 480 * 240 / 160 = 720px
Edit - adding xhdpi as they are becoming more popular
xhdpi
Vertical = 960 * 320 / 160 = 1920px
Horizontal = 720 * 320 / 160 = 1440px
Keep it simple silly
You are already aware about the usage of different folders to provide alternative resources and images to the application.so just go with it.add it to your application.
and now the next step is,
Just design your layout files and look at its Graphical Layout for Preview All Screen Sizes.
Now,Check->Analyse->Change if required
And you're done :-)
values-w360dp
values-w360dp-xhdpi
values-w360dp-xxhdpi
drawable-w360dp
for better reference , read this thread.
http://developer.android.com/guide/practices/screens_support.html
public static int convertDpToPx(int dp,Context context)
{
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
return (int)px;
}
public static int convertPxoDp (int pixel,Context context)
{
float density = context.getResources().getDisplayMetrics().density;
int minHeight = (int) (pixel*density + 0.5f);
return minHeight;
}
There is need of any other folder than these folders?
There is no "need" to put any of the extra folders actually. Create them only if you need them and only if you want to provide a different layout/resources for the specific device. For example if you have a list view whose items open a detail view (activity) on a phone, you might want a separate layout for tablets(xlarge for example) that has only 1 activity with 2 fragments side by side.
Am I doing right?
Can you test it now? Do you have any problems running your app on different devices?
How to convert resolution from ppi to dpi?
Can't give you an exact formula, but you can find more info about DPI and PPI in wikipedia.

if no xxhdpi resources are in the folder?

if i have resources in all of the folders except the xxhdpi folder will xxhdpi devices take from one of the other folders as a default? in other words do i have to make resources for xxhdpi folder? i have this chart but im not sure of xxhdpi im trying to be enlightened a little
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
Generalised Dpi values for screens:
ldpi Resources for low-density (ldpi) screens (~120dpi)
mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).
Therefore generalised size of your resources (assuming they are full screen):
ldpi
Vertical = 426 * 120 / 160 = 319.5px
Horizontal = 320 * 120 / 160 = 240px
mdpi
Vertical = 470 * 160 / 160 = 470px
Horizontal = 320 * 160 / 160 = 320px
hdpi
Vertical = 640 * 240 / 160 = 960px
Horizontal = 480 * 240 / 160 = 720px
xhdpi
Vertical = 960 * 320 / 160 = 1920px
Horizontal = 720 * 320 / 160 = 1440px
px = dp*dpi/160
If you don't have any xxhdpi resources it will try to take resources from the "best" source possible.
from the google developer site:
The system uses the appropriate alternative resource
Based on the size and density of the current screen, the system uses
any size- and density-specific resource provided in your application.
For example, if the device has a high-density screen and the
application requests a drawable resource, the system looks for a
drawable resource directory that best matches the device
configuration. Depending on the other alternative resources available,
a resource directory with the hdpi qualifier (such as drawable-hdpi/)
might be the best match, so the system uses the drawable resource from
this directory.
If no matching resource is available, the system uses
the default resource and scales it up or down as needed to match the
current screen size and density
The "default" resources are those that are not tagged with a
configuration qualifier. For example, the resources in drawable/ are
the default drawable resources. The system assumes that default
resources are designed for the baseline screen size and density, which
is a normal screen size and a medium density. As such, the system
scales default density resources up for high-density screens and down
for low-density screens, as appropriate.

How do I prepare images for all the Android resolutions?

In iOS preparing graphics is simple. There are either a normal image (height x width) or a retina image which is #2x (2 times height x 2 times width).
However, since I'm new to Android, I see a ton of drawable-* folders in Eclipse where the * can be "hdpi" or "ldpi" or "mdpi" or "xhdpi" or "xxhdpi". Can someone very clearly and simply list for me what I must do to satisfy each of the display possibilities so my images will look right in each instance? I'm envisioning an answer will be a bullet list with each "*" listed and a sub-bullet list including the things that must be done.
I'd also really enjoy an answer that would start with the highest density and greatest dimension image and working down since I'll be creating in Photoshop and will be reducing quality from a master image.
i got this off of this site a while back, it still comes in handy
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
Generalised Dpi values for screens:
ldpi Resources for low-density (ldpi) screens (~120dpi)
mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).
Therefore generalised size of your resources (assuming they are full screen):
ldpi
Vertical = 426 * 120 / 160 = 319.5px
Horizontal = 320 * 120 / 160 = 240px
mdpi
Vertical = 470 * 160 / 160 = 470px
Horizontal = 320 * 160 / 160 = 320px
hdpi
Vertical = 640 * 240 / 160 = 960px
Horizontal = 480 * 240 / 160 = 720px
xhdpi
Vertical = 960 * 320 / 160 = 1920px
Horizontal = 720 * 320 / 160 = 1440px
px = dp*dpi/160
In Android Studio just go to File -> New -> Image Asset and create your images right out of the IDE.
On Android we usually handle image sizes in units of "dp" or "dip" which stands for device independent pixel. 1 dip = 1 pixel, on a mdpi screen. There are loads of devices out there with different screen densities, not just normal and retina, so there are multiple DPI buckets a device's screen may fall into:
ldpi (low dpi): around 120 dpi
mdpi (medium dpi): around 160 dpi
hdpi (high dpi): around 240 dpi
xhdpi (xtra high dpi): around 320 dpi
Note that these are buckets, so a device with a 170 dpi screen will count as an mdpi device.
Let's say that you have a vector based image in PS and you need to create an image resource for Android and you'd like to support all these screen densities. Let's say that image needs to be 100x100 dip large. So you create a 100x100 pixel version for mdpi, a 150x150 pixel version for hdpi, 200x200 for xhdpi, and 75x75 for ldpi. You can think of "mdpi - xhdpi" on Android as "normal - retina" on iOS.
As for the larges image size that you can use, I really can't say. There's no hard limit as far as I know, but the device obviously won't be able to load a 20000x20000 bitmap into memory without downsampling because of heap limits.
There is an online tool for that Android Asset Studio
And also there is File|New|Android Icon Set in Eclipse

How do I figure out what size (in pixels) an image needs to be for Android to display that image correctly across devices?

I have two images I want to display within my app.
The first image is to be full screen (as a background for the app). I have read the 'Supporting Multiple Screens' article on developers.android.com multiple times but, I am still at a loss as to what size the image should be for each dpi category. I have attempted what I thought to be the correct sizes but, when viewing the app on larger screens (ie. 1280x800#mdpi), I find that the background appears pixelated. This is understandable since my image for mpdi is 320x480px. How can I correct this? What size image should I use?
The second image is a button. Currently I have the image at a very high resolution but, the app scales this down so it looks fine. However, I do not wish for it to be this way when the app is released. For this image, I need to know what size in pixels the image should be. Currently, it is 60dp x 50dp within the app. What would this convert to in pixels? I know to use the formula px = dp * (dpi / 160) but, what would the dpi be in this case? I cannot use a NinePatch PNG for this image.
I do not understand what size (in pixels) to make my images to begin with so that they appear correctly on Android devices. Does dp = px if you are on a mdpi device?
UPDATE:
After hours of banging my head around, I have came up with the following:
drawable-xlarge-xhdpi 2560x1920px
drawable-large-xhdpi 1920x1440px
drawable-normal-xhdpi 1280x960px
drawable-xlarge-hdpi 1920x1440px
drawable-large-hdpi 1440x1080px
drawable-normal-hdpi 960x720px
drawable-xlarge-mdpi 1280x960px
drawable-large-mdpi 960x720px
drawable-normal-mdpi 640x480px
drawable-xlarge-ldpi 960x720px
drawable-large-ldpi 720x540px
drawable-normal-ldpi 480x360px
These will be my drawable directories and the maximum resolution I expect for each one (I've decided not to support small screens). Therefore, my images will be these sizes.
It looks great on my phone. I see no artifacts. It also appears to work on the emulator for a screen with 1280x800#mpdi so hopefully it will work on all devices...
Does anyone see a problem with doing it this way? Is there a better way to do this? Do my calculations look correct?
here you go, i got it off here, im just passing it along
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
Generalised Dpi values for screens:
ldpi Resources for low-density (ldpi) screens (~120dpi)
mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).
Therefore generalised size of your resources (assuming they are full screen):
ldpi
Vertical = 426 * 120 / 160 = 319.5px
Horizontal = 320 * 120 / 160 = 240px
mdpi
Vertical = 470 * 160 / 160 = 470px
Horizontal = 320 * 160 / 160 = 320px
hdpi
Vertical = 640 * 240 / 160 = 960px
Horizontal = 480 * 240 / 160 = 720px
xhdpi
Vertical = 960 * 320 / 160 = 1920px
Horizontal = 720 * 320 / 160 = 1440px
px = dp*dpi/160
Use method in JRowan's answer and you can add desired images for "special" screens to res folders like here:
res/drawable-xlarge-mdpi/background.png
or
res/drawable-sw600dp-mdpi/background.png
...

Generating Images In Specific Screen Size Densities

I'm building an app with one image file that is used throughout the apps views. I'm a little confused about the information in android.developers in regards to scaling images to the different screen densities in Android: ldpi = 0.75; mdpi = 1.0; hdpi = 1.5; xhdpi = 2.0.
My first thought was that all I had to do was insert the image file to the appropriate density files, and Android would take care of the scaling thereafter; but I don't feel this is correct. My question is:
If I'm wrong, and I have to scale the image to the appropriate densities myself, and then save them to the different density files, how would I do this? Would I be able to do this in Photoshop? I'm thinking yes, but I'm not sure. If so, how would I scale an image? Thanks for any help!
Here you go, this might help, I got it off of here, it comes in handy sometimes:
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
Generalised dpi values for screens:
ldpi resources for low-density (ldpi) screens (~120dpi)
mdpi resources for medium-density (mdpi) screens (~160dpi) (this is the baseline density)
hdpi resources for high-density (hdpi) screens (~240dpi)
xhdpi resources for extra high-density (xhdpi) screens (~320dpi)
Therefore generalised size of your resources (assuming they are full screen):
ldpi
Vertical = 426 * 120 / 160 = 319.5px
Horizontal = 320 * 120 / 160 = 240px
mdpi
Vertical = 470 * 160 / 160 = 470px
Horizontal = 320 * 160 / 160 = 320px
hdpi
Vertical = 640 * 240 / 160 = 960px
Horizontal = 480 * 240 / 160 = 720px
xhdpi
Vertical = 960 * 320 / 160 = 1920px
Horizontal = 720 * 320 / 160 = 1440px
Formula used:
px = dp*dpi/160
If you want to let Android scale (which I don't recommend) you can simply place one image only in the appropriate density folder (preferably the highest you support -- xhdpi probably for now) and Android will scale it.
Preferably yes, you should rescale them beforehand in Photoshop/GIMP/editor of choice.

Categories

Resources