How to handle images especially background images in android - android

I want to know how to handle images in android. How I am able to put image with correct dimensions. What is the resolution of images?

Please read the Android Documentation regarding screen sizes.
From a base image size, there is a 3:4:6:8:12:16 scaling ratio in drawable size by DPI.
LDPI - 0.75x
MDPI - Original size // means 1.0x here
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x
For example, 100x100px image on a MDPI will be the same size of a 200x200px on a XHDPI screen.
You can see the different size for different resolations here :
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

Does every Android screen have the same dpi?

I seem to be very confused after reading the Android Developer Supporting Multiple Screens. I thought the dpi was the amount of pixels on each respected screen in order to make the rendered object appear the same on every screen. So, in a way this means dpi is basically a percentage of the screen? For example, if I move an object 10dp in a south bound direction is this basically moving the object a percent of the screen south?
I also thought the dp was a scaled version of pixels to a medium size screen. So does this mean every android device has the same dp screen size?
Some background info:I am trying to develop a game. In this game objects are falling down the screen. So I would like the objects to appear to be falling and moving around the screen at relatively the same speed on every Android device. Any tips or info to help me get on track or am I way off in my approach?
The current methods I am using for conversions:
public static int dpToPx(Context context, float dp) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
int px = Math.round(dp * (displayMetrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT));
return px;
}
public static int pxToDp(Context context, float px) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
int dp = Math.round(px / (displayMetrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT));
return dp;
}
what i would do is get the width and height of the device and than use fractions of that, then it will be the same on all devices
here i got this off of this site maybe it will come in handy for you
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
for full information please visit
http://www.captechconsulting.com/blog/steven-byle/understanding-density-independence-android

Best Screen Resolution to test Android Game

I am building a game for Android. I want to test it for as many phone and tablet resolutions as possible. Can somebody tell me what are the main resolutions i need to test so that i can be assured of it running fine on all Android supported phones and tables.
I am looking for something like 1024x768... etc. This is because I can set the resolution in unity and test it on my screen.
i got this off of here for android maybe this will help
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 want to test it inside the Editor it is better that you set an aspect ratio and rezise the window to your needs. This gives you a flexible tester instead of making static resolutions.

Large - Normal in Multiple Screens Android

Through as Supporting Different Densities , there are 4 types of screens :
xhdpi
hdpi
mdpi
ldpi
I want to know WHAT IS EXACTLY SCREEN SIZE ( in PIXEL ) of these ? :
normal-xhdpi large-xhdpi
normal-hdpi large-hdpi
normal-mdpi large-mdpi
These screen sizes is given by Eclipse :
xhdpi : 768 x 1280
2560 x 1600
720 x 1280
hdpi : 480 x 800
480 x 854
mdpi : 1280 x 800
1024 x 600
480 x 854
480 x 800
320 x 480
See you are mixing the concepts. small,medium,large and xlarge are screen sizes whereas ldpi,mdpi,hdpi , xhdpi,nodpi and tvdpi are screen densities
According to Android Developer's website
SIZE
small - Resources for small size screens.
normal - Resources for normal size screens. (This is the baseline size.)
large - Resources for large size screens.
xlarge - Resources for extra large size screens.
Density
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).
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.
tvdpi Resources for screens somewhere between mdpi and hdpi; approximately
213dpi. This is not considered a "primary" density group. It is mostly
intended for televisions and most apps shouldn't need it—providing mdpi and
hdpi resources is sufficient for most apps and the system will scale them as
appropriate. If you find it necessary to provide tvdpi resources,
you should size them at a factor of 1.33*mdpi.
For example, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi.
Now the minimum resolution of each size is defined below
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
Also from the android Docs
The conversion of dp units to screen pixels is simple: pixels = dps * (density / 160). For example, on 240 dpi screen, 1 dp would equal 1.5 physical pixels. Using dp units to define your application’s UI is highly recommended, as a way of ensuring proper display of your UI on different screens.
Which means two different devices with different densities can have the same number of dp but not same pixels.
This Formula worked for me to get the screen size and convert them into pixels :
float scale = getBaseContext().getResources().getDisplayMetrics().density;
int pixels = (int) (120 * scale + 0.5f);

background image size for mobile devices

I want to show a background image in my andriod application.
What is the ideal image size (width and height) to fit in all screen resolutions for mobile?
id say ideal would be to use the highest screen density so the app will scale it down for lower screen resolutions that way you wont loose quality on bigger screens, heres the chart i got off of here
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
please refer following links..
Support multiple screens
Best practise
testing for multiple screens
This along with #JRowan answer will guide you in proper direction..

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