I want to use background image in my app.But i am so confused about different screen sizes.I found this question:
Android: Background Image Size (in Pixel) which Support All Devices
But in answer he said xxxhdpi: 1280x1920 px but Lg G3 is xxxHdpi and screen resolution: 1440 x 2560
I need a roadmap.How should be my image sizes for all screens ? (mdpi,hdpi,xhdpi etc.)
Android devices' screen sizes in pixels and screen width in inches, can differ significantly from device to device.
To address this issue, google lets you use different resources per size/density category
See here for some more info.
Generally speaking, you must put the largest size image that you want to support for each dpi in the correct folder, and let android do the resizing.
You can also check the imageView's ScaleType attribute to choose how to scale the image to fit the view.
EDIT
the reason to use the different folders and not just one large image is that the larger the image, the more memory it consumes.
For example a 1920x1280 image is nice to have on a 1920 screen, but on a 320pixels screen the extra resolution is wasted and you have a lot of wasted memory used.
An easier way is to include one single image in your drawable directory, then, in the OnCreate function of your activity, create a bitmap to fit the screen and put it in an imageview that has width and height set to "wrap_content".
This should work for any device.
Read this link. In particular, I think what you're looking for is:
To create alternative bitmap drawables for different densities, you should follow the 3:4:6:8:12:16 scaling ratio between the six generalized densities. For example, if you have a bitmap drawable that's 48x48 pixels for medium-density screens, all the different sizes should be:
36x36 (0.75x) for low-density
48x48 (1.0x baseline) for medium-density
72x72 (1.5x) for high-density
96x96 (2.0x) for extra-high-density
180x180 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density
and also:
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
Related
I've read so much about these things already, so many threads, but there still some things that I don't understand about how to, as a both developer and a designer, avoid problems with different sized screens.
So my question is mainly: What is the difference between putting drawables into mdpi,hdpi,xhdpi,xxhdpi folders as opposed to normal,large,xlarge folders? Should I do both?
I want drawables to act like this: If it takes 50% of the width of the screen on a smartphone, it should take 50% of the screen on a tablet. That's where I'm also confused - Both my phone and tablet are 1920x1080 and both fall into the xhdpi bucket (I believe), but their physical screen sizes are very much different.
Now I save drawables according to the mdpi, hdpi... ratios. Therefore I get results like this on the phone:
When I just out of curiosity created folders for drawables large and xlarge (I didn't know the ratios), I get this, which is closer to what I'm aiming for (but is obviously too big):
But what's the point of using the xhdpi (etc) buckets? Am I understanding this completely wrong? Someone please enlighten me. I hope this question makes sense. My point is - I want the scales of text and pictures to fill about as much of the screen on a tablet as on a smartphone.
Thanks
We developers just create drawbles for mdpi, hdpi, xhdpi, xxhdpi because screen resolution of devices maybe different. While in the case of the normal, large, xlarge folders it is used for the case of screen sizes.We Use This configuration qualifiers (mdpi, hdpi, xhdpi, xxhdpi) because for example for low budget phone, resolution maybe less and will show 48px drawable bigger while high end devices will show it smaller. That's why we create drawables for different resolutions of phones varying from 42(maybe) to 192 px.Similarly normal,large,xlarge folders are used in respect with screen size.
If you want to compress app size, you may use vector drawables. They are just created for one time and look consistent on every time.For Custom icons, export it to .svg or .psd format and create it as vector drawable through android studio.
Edit : I usually create my logo on Photoshop and android studio efficiently exports it to vector drawable.
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.
Vector drawables are put in drawables folder. There is one more advantage of using vector drawables that is one May animate it.
Note : Beginning with Android 3.2 (API level 13), these size groups small, normal, large,xlarge folders are deprecated in favor of a new technique for managing screen sizes based on the available screen width. If you're developing for Android 3.2 and greater use mdpi,hdpi,xhdpi,xxhdpi folders.
The configuration qualifiers (described in detail below) that you can use for density-specific resources are ldpi (low), mdpi (medium), hdpi (high), xhdpi extra-high), xxhdpi (extra-extra-high), and xxxhdpi (extra-extra-extra-high).
Screen Density of devices
A set of six generalized densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
Images Sizes as per folders.
36x36 (0.75x) for low-density
48x48 (1.0x baseline) for medium-density
72x72 (1.5x) for high-density
96x96 (2.0x) for extra-high-density
144x144 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density. Hope this will help.You ask me more about this in detail in comments.
I have PSD, resolution of that is 1080X1920, it contains a Dot image whose resolution is 22X22.
I have cropped that image and put it in my res folder.
My question is how would Android know that the image is for 1080X1920 screen. It would open the same image bigger in small screen and smaller in 2560x1440 resolution.
Is there a way other than putting different images for each screen sizes to tell android to use the image for specific screen size and scale for other screens
use directly https://romannurik.github.io/AndroidAssetStudio/
For example, two devices that both report a screen size of normal
might have actual screen sizes and aspect ratios that are slightly
different when measured by hand. Similarly, two devices that report a
screen density of hdpi might have real pixel densities that are
slightly different. Android makes these differences abstract to
applications, so you can provide UI designed for the generalized sizes
and densities and let the system handle any final adjustments as
necessary
You have to create different dimen , layout , images and icon files to support all devices.
changes in screen density.
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
Make this layout files, so that it will be same for all devices.
Give padding ,margin ,font and all properties as per devices.
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
For Layout ,
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra-large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra-large in landscape orientation
For Images
res/drawable-mdpi/graphic.png // bitmap for medium-density
res/drawable-hdpi/graphic.png // bitmap for high-density
res/drawable-xhdpi/graphic.png // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png // bitmap for extra-extra-high-density
For Icon
res/mipmap-mdpi/my_icon.png // launcher icon for medium-density
res/mipmap-hdpi/my_icon.png // launcher icon for high-density
res/mipmap-xhdpi/my_icon.png // launcher icon for extra-high-density
res/mipmap-xxhdpi/my_icon.png // launcher icon for extra-extra-high-density
res/mipmap-xxxhdpi/my_icon.png // launcher icon for extra-extra-extra-high-density
For Launcher icon
36x36 (0.75x) for low-density
48x48 (1.0x baseline) for medium-density
72x72 (1.5x) for high-density
96x96 (2.0x) for extra-high-density
180x180 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density (launcher icon only; see note above)
Checkout Dimension and
Supporting Multiple Screens Official Documentaion.
Android Studio has a plugin called "Batch Drawable" install in your Android studio. This help to create images of different size.
Steps To import:
File-->Settings-->Plugin-->Browse Repositories-->Click install button.
Restart your Android studio, then you will be able to find "Batch Drawable" inside the file menu of Android Studio.
Link: https://github.com/winterDroid/android-drawable-importer-intellij-plugin
There is no more you have to do, just put the different resolution files into different drawable-xxx file is okay. Remember that all the pics MUST HAVE the same name but Android will not automatically to match the screen size for each pic is the file name is not matched. Good luck!
put largescale image in drawable folder.
I'm a little confused about how to determine which phones support what layout types. I've done some research but haven't found a satisfying answer.
For example, I've found the below guide:
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
However, I still have some concerns:
Samsung grand (480*800) and HTC wild fire S (320*480) both support MDPI. These screens have very different resolutions, yet have the same layout type?
Galaxy note 2 (1280*720) support HDPI. If HD (720p) is only HDPI, when what device/resolution supports XHDPI?
I've already asked a related question here: How to set layout on 7" two different tablet?.
My most important question, however, is this: How do I know which devices or screen resolutions support each layout type?
Android treats mdpi (160 pixels/inch) as the base density. So for mdpi devices, 1 dp = 1 pixel. At higher densities, there are more pixels per inch (240 for hdpi, 320 for xhdpi).
AutoMatic Scaling by Android itself:
Android attempts to make graphic images occupy the same physical dimensions on the screen regardless of the device pixel density. So if all it finds is an mdpi resource, and the device is hdpi, it will scale the graphic by 240/160 = 150%, and it will double the size of the graphic for xhdpi.
Using different versions of graphics :
If you don't want this automatic scaling (which can make graphics look poor), you can simply supply your own version of graphic resources for use at higher densities. These graphics should be of the same size that Android would scale an mdpi resource.
Note : the pixels/inch that was stored in the image file has nothing to do with this. It's all based on where you put the graphics files in the resources directory for your project. Any graphics placed in res/drawable are assumed to be properly sized for mdpi displays, as are graphics placed in res/drawable-mdpi. Image files that it finds in res/drawable-hdpi are assumed to be properly sized for hdpi displays, etc. When your program runs on a particular device, Android will first look for a graphic that matches the display density of that device. If it does not find one but instead finds one for a different density, it will use that and automatically scale the image based on the above rules.
As the ldpi, mdpi and hdpi refer to screen density, which means how much pixels can fit into a single inch.
the ratio in pixels between them is:
ldpi = 1:0.75
mdpi = 1:1
hdpi = 1:1.5
xhdpi = 1:2
xxhdpi = 1:3
so lets take an image with about the size of 100X100:
for mdpi it should be 100X100
for ldpi it should be 75X75
for hdpi it should be 150X150
for xhdpi it should be 200X200
for xxhdpi it should be 300X300
this way, for screens with the same size but different DPI, all the images seem the same size on screen.
look into these details: android manages all this by itself, you just have to provide layouts and images in relative folders
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
My app has a background image and I would like to create different files of it for the sake of multiple screen support.
I sent this link (http://developer.android.com/guide/practices/screens_support.html) for a graphic designer but he asked me the dimensions in pixels that I want the images to be created with.
Considering that I have a graphic designer in my team and I don’t want to use a code to optimize the images loaded in memory (I only want to place the images in the correct folders for small, normal, large and xlarge screens), what are the most optimized size and dpi settings to generate it?
We are working with PNG files.
For the dpi we are following this:
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).
But for the dimensions I could only find this, which is in dp and not in px:
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
1 dp = 1 px on 160dpi screen.
But your best bet for screen dimens is to look here
http://developer.android.com/guide/practices/screens_support.html#testing
and scroll down to where is shows the screen dimens in pixels (eg: 1920x1080) (Table 3)
Then check which ones you need most by looking at the chart
http://developer.android.com/about/dashboards/index.html#Screens
but the first link will give you the most used screen dimensions in use by Android devices.
I am designing a background for my app for all Android devices.
I was thinking what would be the size of the image in pixels?
From the developer site I found the following equation
px = dp * (dpi / 160)
Then, px depends on two variables.
First, dp, and we have
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
Second, dpi and we have
low-density (ldpi) screens (~120dpi).
medium-density (mdpi) screens (~160dpi).
high-density (hdpi) screens (~240dpi).
extra high-density (xhdpi) screens (~320dpi).
So where should I put my drawables in the Screen characteristic? I mean should I use "size" or "Density". If I classify my images using the "size" "dp", what is the dpi for these images?
and if I classify my images using the "density" "dpi", what is the dp for these images?
I am confused on how to finally size my images. Also, Maybe you can have a medium density screen with a large screen size, right?
There are many many different resolutions out there. For instance there could be 4 different devices which are:
640 px x 480 px
The difference is, some of these devices are mdpi, some are hdpi, xhdpi etc. meaning they could be described as "large", "medium" or "xlarge" screen types.
So, for an mdpi device which is 640x480dp the background would be 640x480px however, a device which is 640x480dp and hdpi would need a background which is 960x720px, you'll notice they're the same size "bucket" but have different densities and therefore different resolutions.
So, if you just want your background to fit as well as can be expected you'll need:
large-xhdpi
large-tvdpi
large-hdpi
large-mdpi
large-ldpi
(then the same for normal)
normal-xhdpi
normal-tvdpi
etc etc etc.
You're best bet however is to use an image which can stretch, a shape, tile or can be converted to a 9-patch because it would be a pain in the rump to make every background available for every device. If you were going to do it I would look up a resource descrivbing every screen dimension on the market currently and setting it via programmatic methods.