Using multiple images in layout android - android

In my application I want to create a layout as shown below I am confused about what size of images should I keep in my resource folder.

A 1.5 inch wide mdpi display is about 240px wide but considering variable sizes for android devices I'd say to fill your screen an image 400px wide should be safe to use on mdpi devices. Scale height according to the required aspect ratio and scale both dimensions for different densities(ldpi, mdpi, hdpi, xhdpi, xxhdpi) accordingly.

Related

Designing icons for android

I did some research and found that there 6 different sizes required by Android to display images properly on all sorts of devices.
LDPI - 0.75x
MDPI - Original size
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x
So suppose I have 100x100 image as a baseline (MDPI), then ldpi, hdpi, xhdpi, xxhdpi will be as follows.
LDPI - 75x75
HDPI - 150x150
XHDPI - 200x200
XXHDPI - 300x300
XXXHDPI - 400x400
But I have confusion as to what should be the baseline(mdpi). How do I select my baseline, does it have to be based on something? I can have different images in my app example a back arrow, home arrow, a background image(full screen), an Add icon and so on. But all these icons have to different sizes. So how can I choose my baseline size?
No need to choose, the mdpi(baseline) density means that one dp is roughly equal to one pixel. So we call it the baseline density.
If we provide icon with size by the definition. We will get all the icon image have same physical size on different density screen(ldpi,mdpi,xdpi and so on) with proper quality.
About the background image, I would recommend to put the background image to drawable-nodpi which the image just fill entire screen no matter the density, so just put it there to let the system don`t scale the image and save some memory resources to scale it.
reference Support different pixel densities
Check if this can help you,
Material design icons

How to maintain imageview size and font size across the screen resolution including tablet

I am new to android and trying to figure out how to set logo and font size across all the screen resolution. For XHDPI resolution my logo size is 60 dp and font size is 23sp. I know that MDPI resoultion is half of XHDPI resolution and XXHDPI resolution is double of what XHDPI resolution but these ratios are not working as per my expectation also i need to maintain same aspect ratio for tablet as well. Please help me out here
Define the image sizes in dimensions.xml file.
Create a different dimensions.xml files for different resolutions. Ex;-
values - dimen.xml
values-sw600 - dimensions.xml
values-sw720 - dimensions.xml
you can use the constraints layout (check here)
or you can create different layouts depending on the screen size. (here)

Android : How to create images for different sizes and densities?

I have an image view which has different size on normal and large sized screens(I achived it via dimens.xml), lets assume 100*100 dp on small and 133*133 dp on large sized screen.
I'm setting image to it programatically, let's say it is def.png
Now for best performance I should create 6 versions of def.png(assuming i cater only to mdpi, hdpi and xhdpi densities)
small-mdpi - 100*100 px
small-hdpi - 150*150 px
small-xhdpi - 200*200 px
large-mdpi - 133*133 px
large-hdpi - 199*199 px
large-xhdpi - 266*266 px
It means 6 def.png images, but I can put 3 of them because only 3 folders are available i.e. drawable-mdpi, drawable-hdpi, drawable-xhdpi.
How should I achieve best performance so that there will be less scaling up and down of Images ??
or
If it is not possible this way, then what are the alternatives ?
How to Support Multiple Screens:-
Explicitly declare in the manifest which screen sizes your
application supports
Provide different layouts for different screen
sizes
Provide different bitmap drawables for different screen
densities
Source :- https://developer.android.com/guide/practices/screens_support.html#support

Working with different screen sizes and different densities for resource drawables

I'm preparing drawables for my app. After some research, I came to know that 3 parameters that needs to be considered are Screen-size, Density and Resolution.
1.) Since for a particular screen-size, if density varies then corresponding resolution will automatically vary. Also, for a particular density, if screen-size varies then corresponding resolution will automatically vary.
Going by this logic, I removed resolution from consideration and planned to concentrate only on screen-size and density. Am I correct in this approach?
2.) Now as per documentation, if you are preparing 100x100 image for mdpi, then you should have 75x75 and 150x150 image for ldpi and hdpi respectively.
So I created an image resource drawable (.png) of size 100x100 with density 160 (mdpi). Then I created the same image with size 75x75 with density 120 (ldpi) and 150x150 with density 240 (hdpi) and placed them in respective drawables folders.
But after doing this, when I run the app on emulators having combination of different screen-size and different densities, the drawables just doesn't fit-in properly in the given space.
In some smaller screen-sizes, 3rd icon is getting cut halfway through.
Am I doing something wrong?
Any help appreciated.
Refer this:
You have to put your images in res/drawable folder by convention.
In res folder there could be more than one drawable folder like res/drawable-ldpi, res/drawable-mdpi, res/drawable-hdpi, res/drawable-xhdpi, and res/drawable-tvdpi.
You might be creating an app for different phones with different screen resolutions and screen sizes.
Android have a categorization of phone screens according to the dpi of the screen, namely ldpi, mdpi, hdpi, xhdpi, tvdpi (low, med, high, xtra high, tv respectively).
Your goal is to add each copy of images to these folders for each type of your target devices. For that you have to resize your images in the dpi ratio.
3:4:6:8 is the default dpi scaling ratio
More

Android screen sizes in Pixels for ldpi, mdpi, hpdi?

I've read 10 articles yet still cant find any relation between ldpi, mdpi, hdpi and the actual dimensions in pixels!? Can anybody give a straightforward answer please(if there is one!)
I'm basically trying to put together a splash screen that needs to work on multiple devices without stretching - but i'm struggling as everything I try is either squashed or stretched!?
Cheers
Paul
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
xxxhdpi = 1:4
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
for xxxhdpi it should be 400X400
this way, for screens with the same size but different DPI, all the images seem the same size on screen.
Also you have multiple screen size types small, normal, large, xlarge and each one of them can be ldpi, mdpi, hdpi, xhdpi, xxhdpi (Nexus 10) or xxxhdpi.
You can try to create a splash screen image that fit to each and every screen type
which gives you 4*5 = 20 different images (it seems to much for me).
For now only the Nexus 10 is at the xxhdpi category.
Install ImageMagick and use this shell script to generate your splash and icon files for multiple devices - iOS, Android, Bada and Windows Phone. You can use cygwin/gitbash if you are on Windows
I just did and I'm pretty happy with it :-)
The screen sizes are inside the script and are -
480x800 - screen-hdpi-portrait.png
320x200 - screen-ldpi-landscape.png
720x1280 - screen-xhdpi-portrait.png
320x480 - screen-mdpi-portrait.png
480x320 - screen-mdpi-landscape.png
200x320 - screen-ldpi-portrait.png
800x480 - screen-hdpi-landscape.png
The definitions are:
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. (Android does not currently
support screens smaller than this.)
Also, check out this blogpost from Dianne Hackborne:
http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html
Probably the easiest thing is to use an image view and set the scaletype to CENTER_CROP.
(Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view).
Make sure that you use the src tag rather than setting the background.
<ImageView
android:id="#+id/home_video_layout"
android:src="#drawable/splash_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
/>
Updated:
Understanding Screen Densities and the “dp”
Resolution is the actual number of pixels available in the display, density is how many pixels appear within a constant area of the display, and size is the amount of physical space available for displaying your interface. These are interrelated: increase the resolution and density together, and size stays about the same. This is why the 320x480 screen on a G1 and 480x800 screen on a Droid are both the same screen size: the 480x800 screen has more pixels, but it is also higher density.
To remove the size/density calculations from the picture, the Android framework works wherever possible in terms of "dp" units, which are corrected for density. In medium-density ("mdpi") screens, which correspond to the original Android phones, physical pixels are identical to dp's; the devices’ dimensions are 320x480 in either scale. A more recent phone might have physical-pixel dimensions of 480x800 but be a high-density device. The conversion factor from hdpi to mdpi in this case is 1.5, so for a developer's purposes, the device is 320x533 in dp's.
I have found this online dip <--> pixels calculator very useful.
https://pixplicity.com/dp-px-converter/
I support previous answers but don't forget the power of Draw9Patch or using NinePatchDrawables
These refer to screen pixel density, not screen dimension. You need to look into screen size specifiers like small, medium, large, and xlarge instead if you really need to change behavior based on screen size in pixels.
The Android docs explain what densities and sizes match these identifiers.
Android devices can have different width-to-height ratios, while your image has a fixed one. If you do not want your image stretched, you will have to fill the blank spaces above and below or left and right.

Categories

Resources