Ok so I know questions about resources for different densities have already been asked, however I ran into a problem, which is why this question is different. Ok so on the android developers website here http://developer.android.com/training/multiscreen/screendensities.html it's stated to use the scale of 1.0 for mdpi, 1.5 for hdpi, 2.0 for xhpdi, and so forth. But the problem is this scale appears to be wrong. If I make an image that is 480x800 for the nexus 1, it will take up the entire screen. If I divide this by 1.5 to get the mdpi version which is the baseline, I will get 320x533.34 approximately. Now lets try multiplying this by 2.0 to get xhdpi version. You will get 640x1066.68. In other words, on a nexus 4 with xdpi and resolution of 768x1280, the image will NOT take up the whole screen. The scaling is not accurate. So I made an image that takes up the whole screen of the nexus 1, then scaled it according the the scale given by the android developers, and for other screens the image will not take up the whole screen. I want a scale that will give me complete accuracy. Thanks!
In other words, on a nexus 4 with xdpi and resolution of 768x1280, the image will NOT take up the whole screen
It is not supposed to. Density has nothing to do with screen size. I can have an -xhdpi screen that is one inch, one foot, one meter, one mile, or one parsec in diagonal length. Those screens would have drastically different resolutions, but the density would be the same.
MDPI is 1.0 as you said, not 1.5. If you create an image that is 480x800 in the MDPI folder, it will be scaled up to 720x1200 on an HDPI device, or 960x1600 on an XHDPI device. You're never going to get an image which properly fits all screens -- there are just too many aspect ratios and resolutions to do that properly. Try to avoid that design philosophy altogether if possible (e.g. maybe have a nine-patch image in the center with a stretchable region on the edges), or set the image to scale and crop to fit (e.g. scaleType="centerCrop") and keep important parts of the image away from the sides of the screen to allow for some wiggle room.
Related
I'm making an android App that shows images at full screen.
I learned some about dpi and dp, but I didn't find how many pixel must be the largest side of my images (in prospective to good fit also in landscape mode) to appear good in different devices.
As in the documentation, the most used screen configurations are normal with hdpi, xhdpi and xxhdpi density:
So, if my thinking is correct, I can make only one image to fit the xxhdpi to works fine also with the other two densities, and put it in Android Studio under the "res/drawable" folder (without qualifier).
Specifying the image size in dp in the layout, Android should scale the image for the smaller configurations.
But, for the xxhdpi, how many pixel must be the largest side of my image, in pixel, to show good?
Edit: how many pixel must be the longest side of my image to be showed properly in a device with xxhdpi density without the image appearing grainy?
All images are photo, not icons, so I can't use the vector graphics.
By looking at the Android Documentation. One can estimate the size of the picture. look at below picture
So, your image resolution should be in similar resolution
LDPI: 200 X 320px
MDPI: 320 X 480px
HDPI: 480 X 800px
XHDPI: 720 X 1280px
XXHDPI: 960 X 1600px
XXXHDPI: 1440 x 2560px
A little bit of +/- won't affect the outcome because with these standard sizes the aspect ratio of any portrait picture should be respected.
Well, if you put the image which fits the xxxhdpi inside the folder drawable, then it will fit all the screens.
But there is another way to use only one image instead of using multiple images for different resolutions. It's by using svg images which are vector images that will not be affected by zoom in or zoom out.
To use svg you need to follow these instructions:
Make the icon to be icon.svg
In the Android Studio, right click on drawable folder
Choose New -> Vector Asset
Choose Local File (SVG, PSD)
Choose your svg file
Click Next and choose the name
Click Finish
In the app build.gradle add the following inside android block:
vectorDrawables {
useSupportLibrary true
}
In the xml layout file, add the following:
<AppCompatImageView
android:width="wrap_content"
android:height="wrap_content"
app:srcCompat="#drawable/your_svg_file"
/>
Android have ratios defined for a image to set in all different drawables
Android icons require five separate sizes for different screen pixel densities. Icons for lower resolution are created automatically from the baseline.
mdpi: 160 dpi 1×
hdpi: 240 dpi 1.5×
xhdpi: 320 dpi 2×
xxhdpi: 480 dpi 3×
xxxhdpi:640 dpi 4×
Above size is for normal pixel icons. There are fix android size for Action bar, Dialog & Tab icons, Launcher icons & Notification icons
Check this link for more details http://iconhandbook.co.uk/reference/chart/android/
You have to take a look at the current market of smartphones.
Here you can see the screen sizes and resolutions of the most popular devices in the market.
http://screensiz.es/
Order the list in pixel per inch and you will see that top smartphones have resolutions bigger than 500 ppi or another way to see it, much bigger than 72ppi of your images.
If you have enough space to store or mechanism to download images try to test with full quality. If thats too much try to find a compromise. Lower image quality and see the result in high resolution screen.
Note that you didn't posted here the total size of image, in case is bigger than screen size, take a look at total size of image and compress it to fit your needs, maintaining as much as possible the resolution.
Edit: Looking only to size of image in pixels, the current biggest screen in smartphone is 2560 x 1440 pixels, so you wont need any image bigger than this.
If I understand your answer correctly, you are talking about images (pictures of lovely cats and dogs?) and not about icons?
I prefer putting images into the nodpi folder.
nodpi Resources for all densities. These are density-independent
resources. The system does not scale resources tagged with this
qualifier, regardless of the current screen's density.
Afterwards I would create a fullscreen ImageView and let imageView do the scaling if needed
I want to add a background image to one of the screens of an Android app. (This image is a photo so 9-patch will not work).
I want scale this image for various different resolutions.
Android organises images uses DPI (i.e. ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi). However this does not seem useful in this particular situation as I want to use an image that covers the ENTIRE screen. DPI does not tell me how big the entire screen is. For example, a xxxhdpi screen may have a lower resolution than a ldpi screen.
To illustrate this issue consider the following devices:
Samsung Galaxy Tab 10: mdpi, 800px x 1280px
Moto G: xhdpi, 720px x 1280px
As you can see the first device requires a larger resolution image, despite having a lower dpi.
Therefore my question is, how do I create an image that covers the screen for different screen sizes.
You can find several answer at stackoverflow like: Android: Background Image Size (in Pixel) which Support All Devices
Another reference including tablets can be found at: Is there a list of screen resolutions for all Android based phones and tablets?
The detailed description can be found at: https://developer.android.com/guide/practices/screens_support.html
One point you need to keep in mind is how the image will cover your layout, you need to fit using center crop as scale type.
Remember to leave some space from borders at least not including important information that could be cropped from the border based on the real device size.
Another way to add backgrounds for multiple size and densities is not trying to cover the entire scree just a mix. A gradient plus some image can give you enough flexibility many times.
Another solution is using a blurred image which do not interfere with the rest of the information shown. In this case because of the nature blurred of the image, it is not required to be detailed.
Hope it helps.
I am wondering what would happen if you put for instance one image in only one specific size, let's say image X in hdpi and an other image Y in only resolution size xxhdpi, the size which was "right" for the device was xhdpi. Assuming that the OS decided what was the "right" size for the device.
Will it then downscale the image xxhdpi and upscale hdpi to xhdpi? Or would it only change the size of one image, for instance the one with the lowest resolution remains the same, the higher ones are downscaled?
Quite an interesting question out there!
In this case, the bigger drawable will be taken an downscaled to the device needs.
However, if the device is i.e. xxhdpi and you provide drawables ie. for mdpi and hdpi, the OS will take the hdpi drawable and scale it UP.
Android chooses the one appropriate for the resolution or screen dimensions. ..when it doesn't find one in the right folde than it goes down in the resolution searching for a lower quality folder...again when it doesn't find one in the folder with lower resolutions than it searches in the higher quality....and crashes if there is also none at runtime....AT compiletime you'll get error when thers n no image
Depends on how you display the images....Icons get everytime up or down scaled. ...IT is recommended that you have one and only one xxxhdpi icon in your app because downscaling is better than up scaling due to AA
I apologize for the simple question, but I am a bit confused.
I am creating my first Android app. Functinally I am done. I am now working on the UI. According to this, I am required to provide multiple icons to support different screens and I understand this part.
So I created a vector image, and was about to export it to generate a number of icons to support multiple resolutions. However, I could not find the require DPI. According to this, I am supposed to support different DPIs, but the article does not explain how to do that.
Can you please advise me on how to select the proper DPI? Does it even matter? I thought it does, but maybe my understanding is wrong.
Thanks.
EDIT:
Just to clarify my question. When I am exporting an image from a vector to a raster image, I have to select its dimension (so in my case, 400px X 200px), and its dpi. So what should I choose for DPI? Is that the same DPI that will create different icon sizes? I am confused. Thanks again.
For what concerns dpi, I use to follow the screen dpi:
640 dpi for xxxhdpi screens
480 dpi for xxhdpi screens
320 dpi for xhdpi screens
240 dpi for hdpi screens
160 dpi for mdpi screens
120 dpi for ldpi screens
This way I'm sure the icons are appropriate to the screen resolution.
I'm also sure that I can skip some (if not all) the lower qualities, once I have the highest resolution graphics, because they will scale down nearly perfectly.
But, since I'm a perfectionist, nearly disturbs me.
So, I do provide all the resolutions graphics.
For what concerns dimensions use this cheatsheet: http://petrnohejl.github.io/Android-Cheatsheet-For-Graphic-Designers/#dimensions
You can make this experiment:
for an xhdpi screen, prepare a 800px X 400px image at 72 dpi (and no other images for other resolutions) and see how does it scale down in a lower resolution physical device, say an ldpi screen (it will look really bad)...
Then prepare a 800px X 400px image at 480 dpi (and no other images for other resolutions) and, after scaling (will look very good, on the same ldpi screen), compare the result to the previous one.
The difference will be evident on a physical device, much less on an emulator.
It's a way of doing things when you want to save some bytes on lower resolution pictures: just prepare the highest resolutions ones and let Android scale them down (it will scale down the ones it doesn't find in their folders).
I am writing my conclusion for the greater good. After further reading and investigation. It appears that DPI is not important when I am creating an image for a screen. So when I choose 400px X 200px, and assuming this will be for mdpi, then I should choose 800px X 400px for xdpi (and so on and so forth). The dpi should be ignored in all cases (does not matter if I chloose dpi of 90 or 600, as long as this is not for printing). On the other hand, if I am to print the image, then dpi is important.
EDIT
This is a great article about the topic. Please read it, it explains things very well.
I Have a few general questions about Android screen / DPI / resolution indepence.
Basically, I am taking specifically about sprite-based apps, like ones based on Surfaceview for example.
Every guide I've read (including the official one) says that you should only work with the DPI and not the resolution.
However, what happens when two devices have different DPI's/screen size but the same resolution? Take the Galaxy tab 10.1 (1280 x 800 - DPI aprox 150) and the Galaxy Note (1280 x 800 aprox 285 DPI I think??)
When displaying a sprite of say 50 x 50 on each of these, it will appear to be the same size relative to the screen size. However, if Android grabs a difference size sprite because it detects a different DPI (ie, from LDPI, HDPI etc), then the sprite will appear to be bigger on the Note relative to the screen size than it would on the Tab.
Can anyone please set me straight on this as I just cannot work it out!! Thanks all.
A 50 x 50 sprite on a 150dpi screen will appear much larger than a 50 x 50 sprite on a 285dpi screen. Android's resource resolution algorithm is intended to allow you to define a larger (in pixels) image for use on higher density screens.
If you want the sprite to be the same size relative to the screen regardless of the pixel density, then you can put the images in the drawable-nodpi folder and they won't be scaled by the system. You can even decide which size image to use in code after querying the screen size. (As of 3.2, you can have resource folders that depend on screen pixel size, but I think they will still scale with dpi.)
Screen resolution refers to the screen dimension in pixels. Pixel density refers to how many pixels it takes to fill an inch of screen.