adding image resources and using one as a layout background - android

so im working on my first app and i have a question about images
first off, theres 4 different drawable folders, do i just drop an image into one of them? what is the proper way of adding a resource image?
secondly, i know theres a bunch of different resolutions for phones. should i just use one that is say, 960x720dp? or is there another appropriate way of doing this? i want to add an image as a resource into my project, then use it as the background for my app layout...

The best way is to put 4 different versions of the image in the 4 folders . The simplest way to find out what resolution each folder must have is to use mdpi image as a reference and multiply other 3 like this:
ldpi = mdpi x 0.75
mdpi = this is the reference resolution
hdpi = mdpi x 1.5
xhdpi = mdpi x 2
Example: for an image that has 100 x 80 px as the base image, the other folder sould contain images with the following res:
ldpi = 75 x 60 px
mdpi = 100 x 80 px this is the reference image
hdpi = 150 x 120 px
hhdpi = 200 x 160 px
The best way is to create the biggest image in you image editor that you will need and make smaller variants from that. you can fint you own mathematical formula for the multiplication
If you don't want to put different variants for the image then let Android OS convert the images for you The Android OS will search the reference image in mdpi folder so make sure to put the image in this folder
More info here

You just need to paste your images into drawable folders.
To address different resoulutions, you can place different images into different drawable folders with same name, say for logo.jpg into drawable-ldpi might have image logo.jpg with resolution fit to ldpi, and drawable-mdpi have image logo.jpg with resoluiion fit to mdpi. or if any image must be same for all resolutions then place a single image into any of the drawable folder.

You can do this by adding just one images in any folder but this link of supporting multiple screens and resolution of images provide you the best way to do that. Just read that

Related

Can we use images in one image density without any quality lost? (Android Image Density)

I work on an image sequence animation. I have 75 png files. I want to use images in one size without adding mdpi, hdpi, xhdpi etc types and get the same view on all devices. Is there a way to do this?
Best,
You Can try the following way may help you
(1)use only mipmap-xhdpi folder and create image according to mipmap-xhdpi density requireda and put all in xhdpi.
(2)Use Vector Drawable/Vector Graphic features in Android studio....Please read detail from https://developer.android.com/training/multiscreen/screendensities
(3)Please try to create the nine-patch image...Please read from https://developer.android.com/guide/topics/graphics/drawables#nine-patch.
https://developer.android.com/studio/write/draw9patch

Can't wrap my head around android drawable folders mdpi, xhdpi

I can't wrap my head around the folders mdpi, hdpi, xhdpi and xxhdpi, are they meant for every kind of images or only for icons? The sizes in which my images are stored in there are really small, as you can see in this cheatsheet (click to enlarge):
xhdpi is 96px. In my app 96px looks really blurry (click to enlarge):
So how should I store my image then?
the folders mdpi hdpi xhdpi and xxhdpi, are they meant for every kind of images or only for icons?
Most bitmap drawable resources should get density-specific versions, at least for a few densities.
as you can see in this cheatsheet xhdpi is 96px
I see nothing in there saying that every image must be 96px for xhdpi. The standard action bar height and tab bar heights for xhdpi are 96px. That's it.
In my app 96px looks really blurry.
That image should have a higher resolution, as you are using it in a UI element that is far larger than the action bar or a tab bar.
So how should I store my image then?
Step #1: Determine your desired size for the image, in inches.
Step #2: Determine the resolution for the image in dp, by multiplying the size in inches from Step #1 by 160.
Step #3: Choose what densities you want to create specific artwork for. You might use the "Screen Sizes and Densities" section of the Android device dashboard to give you some ideas.
Step #4: Determine the density-specific resolution for the image in px, for the densities from Step #3, by multiplying the dp value from Step #2 by the size factor shown in the upper-left infographic of that cheatsheet.
Step #5: Create drawable directories for the densities from Step #3 and create your artwork in those, sized based on the values from Step #4.
Drawable folders are meant for all kind of images.
hdpi,mdpi,xhdpi,xxhdpi.xxhdpi are generally used to cover each and every device available in the market place.
nodpi folder is used to store images that can be used in any resolutions
For adding app icon try using the mipmap folders with all these above qualifiers for different size.
placing correct size images in correct folder will definitely work.

Different sized images (with the same name) in one drawable folder

I'm new to android programming and every single somewhat-similar question is from three or so years ago and doesn't really answer my question. Android Studio used to have different drawable folders for different dpi. Now there is only one. So if I have two images with the same name but for different dpi, where do I add them so that during runtime the phone can use the appropriate image?
Also, most android phones now are xhdpi or xxhdpi--do I really need to include any images less than that? And how exactly would I do that? Say, for example, that I get an image off shutterstock. How do I make it so it works correctly for both xhdpi and xxhdpi?
Those folders have not gone anywhere, if you want them you simply create a new folder and name it appropriately ( drawable-xxhdpi etc.. )
Depending on IDE it just does not make them by default under certain circumstances
DENSITY SIZE LOCATION RATIO SCREEN MARGIN
XXXHDPI 192×192 drawable-xxxhdpi 4 640 DPI 12 to 16 pixels
XXHDPI 144×144 drawable-xxhdpi 3 480 DPI 8 to 12 pixels
XHDPI 96×96 drawable-xhdpi 2 320 DPI 6 to 8 pixels
HDPI 72×72 drawable-hdpi 1.5 240 DPI 4 to 6 pixels
MDPI 48×48 drawable-mdpi 1 160 DPI 3 to 4 pixels
MDPI 48×48 drawable (Cupcake) 1 160 DPI 3 to 4 pixels
LDPI 36×36 drawable-ldpi 0.75 120 DPI 2 to 3 pixels
NA 512×512 Google Play NA NA As required
Android Studio used to have different drawable folders for different dpi.
It still does.
Now there is only one.
No, there are several. However, in the "Android" project view, they are shown in a collapsed state:
If you change the drop-down towards the top-left of that screenshot to "Project", you will get the view that you are used to, that mirrors the filesystem:
So if I have two images with the same name but for different dpi, where do I add them so that during runtime the phone can use the appropriate image?
The same place as before. Personally, I find the "Android" project view to be singularly useless, and so I switch to the "Project" view as one of the first things when I open the project.
most android phones now are xhdpi or xxhdpi
No, right now, only about a third are.
do I really need to include any images less than that?
I would. If you have a zillion drawables, you are welcome to experiment with having fewer densities, but you will want to test the lower densities to confirm that the downsampling of your drawables is turning out OK.
Create the folders yourself as you need them. It's true that most phones now are xhdpi but what about your target audience? Are you sure their phones and tablets support xhdpi at minimum? There are some tablets such as the Galaxy Tab 2 which are below these values. Just something to keep in mind. Although, consider using layout-sw(x)dp for devices bigger than 600dpi
You'll have to resize them for the appropriate drawable. Use you should follow the 3:4:6:8:12:16 scaling ratio where 48x48 is the baseline. As an example, in order to support xxxhdpi your drawables would be 192x192
Actually Android Studio also has multiple drawable folders. But It remains wrapped in Project Structure's Android View.
So you see only one Drawable folder.
If you want to see all the drawable folders in expand mode then click on the drop down like below and select "Project":
Now you can navigate the drawable folders like this:

Where should I put background images in different screensizes?

I've been reading about the drawable-XXdpi folders, and I created my icons in all sizes.
What I want to do now, is to put a background image on my main screen. And what my assumption is at this moment, is that I don't work with DP at this moment but with PX, because my background image needs to fill all the pixels.
When this assumption is correct, where do I put my created background images?
I've created one for 480*320, 800*400 to the largest 1600x2560.
In my assumption I can't put them in the drawable-XXdpi folders because those are DPI related, and I need to fill all the pixels.
You can put your drawable that is not specific for each dpi into drawable-nodpi folder.
But basically, as Der Golem describes, you should always use dp.
I don't work with DP at this moment but with PX ... You should always use DP.
To fill all the available space, just use android:background instead of android:src.
Note that the image will be stretched (if you don't make it a 9 patch - this will also be stretched, but in a "controlled manner").
To create a background with the exact pixel size is not a good practice.
You'd end up wit oversized images.
Better practices include (not mutually exclusive - they can be stacked by using a Layer-List):
stretchables (such as 9 patches)
tiles (seamlessly tileable pictures)
drawables (which are vectorial, like SVG files)
These ones include:
a - shapes
b - gradients
c - ...
SVG (through 3rd party libraries)
...
Also consider that "the exact pixel size" might be different from what you expect.
You have to take in account the StatusBar, the ActionBar/ToolBar, the MenuBar, ...
There is no separate folder architecture for putting px files. You need to use drawable-hdpi , drawable-mdpi, drawable-xhdpi, drawable-xxhdpi.
The approximate pixel values for different dps are like this:
ldpi = 600.00px x 360.00px
mdpi = 800.00px x 480.00px
hdpi = 1200.00px x 720.00px
xhdpi = 1600.00px x 960.00px
xxhdpi = 2400.00px x 1440.00px
Check these links for more details:
http://pixplicity.com/dp-px-converter/
http://developer.android.com/guide/practices/screens_support.html

android Supporting Multiple Screens Calculation

I recently had a doubt
I put 40px * 40 px images in drawable folder.
and put 40px * 40 px images in drawable [hdpi] again .
Then Tabhost set this picture
[hdpi] exists and does not exist
Size two pictures displayed on the screen is not the same and why?
They are all the same 40px * 40px
why?
Different folder will result in a different calculation methods it?
PS:[My phone will pre-select [hdpi] folder]
I think you need to create drawable folder in res folder and add all images in drawable folder.
Actually in android there are different resolutions screens and every resolution have fix limitation for retrieving the images on specific folders like - hdpi, ldpi ,mdpi etc. When we create drawable folder in res then if any different resolution screens will occurred then it will pic the image from drawable folder.
If running on mdpi device 150x150 px image will take up 150*150 dp of screen space.
If running on hdpi device 150x150 px image will take up 100*100 dp of screen space.
If running on xhdpi device 150x150 px image will take up 75*75 dp of screen space.
The other way around: say, you want to add an image to your application and you need it to fill 100*100 dp control, you'll need to create different size images for supported screen sizes:
100*100 px image for mdpi
150*150 px image for hdpi
200*200 px image for xhdpi

Categories

Resources