Actionbar icon size not the same on different platforms - android

Here is my setup. Two tablets - 7" and 21". The smaller tablet has a higher DPI.
Two png images. Both the images are 36x36. The first image is copied to drawable-ldpi directory and the second image is copied to drawable-mdpi directory. These images are displayed as menu items in the actionbar.
On 21" tablet, both the images are displayed with the same height. The framework leaves about 10% space on the top and on the bottom of the actionbar.
On 7" tablet, the first image appears bigger than the second image. The bottom of the first image aligns with the bottom of the actionbar.
I am trying to understand how the framework calculates the height of the final bitmap to be displayed. I am developing a custom view and need to do a similar calculation. Thank you in advance for your help.

Two png images. Both the images are 36x36. The first image is copied to drawable-ldpi directory and the second image is copied to drawable-mdpi directory.
First of all, you have to provide the same image with different sizes per device/screen size.
Then, you should create other folders, for instance drawable-large which will handle drawables for large screens like your tablets
Have a look here

Related

Do I need to use all of drawable, drawable-mdpi, drawable-hdpi, drawable-xhdpi, drawable-xxhdpi & drawable-xxxhdpi?

I realise that Android will try it's best if it does not find an icon in the required folder but I see someplaces they suggest all of the above and in others they don't include drawable ?
So should I populate drawable as well if all the others are filled with my tab icon images?
If you use a VectorDrawable, you don't need to add a Resource for every density (mdpi, xhdpi etc). VectorDrawable is supported since API 21 (Lollipop) or with Support Library (or AndroidX).
For simple types of images (usually icons), you can avoid creating separate images for each density by using vector graphics. Because vector graphics define the illustration with geometric line paths instead of pixels, they can be drawn at any size without scaling artifacts.
For images (PNG) on the other hand, you must add proper icons for every density because Android will try to scale the images (so they can proportionally occupy same area in all devices). When scaling, the image may become blurred reducing the quality of your UI.
To provide good graphical qualities on devices with different pixel densities, you should provide multiple versions of each bitmap in your app—one for each density bucket, at a corresponding resolution. Otherwise, Android must scale your bitmap so it occupies the same visible space on each screen, resulting in scaling artifacts such as blurring.
You can read more HERE and HERE
EDIT
Maybe, you don't need to duplicate ALL icons. A lot of factors can lead to different experiences such as using wrap_content or a specific dimension to control the icon size or even using a different scaleType in your ImageView. So, maybe, you can start by adding icons for xhdpi or xxhdpi folders only and check your screen in different screen (small display, large displays, low-resolution displays, high-resolution displays etc). Then, you can "duplicate" only the necessary icons... But if your project or APK size is relatively small, don't mind to duplicate the icons.
There's even some online tools to generate the assets for every density from a single PNG such Android Asset Studio website..
If you are adding all resolution drawable icon like :
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxxdpi
then you need not to add any extra icons on drawable folder
because all the device resolution covers under the above drawable folders

How does Android Studio handle image sizes?

I have an application where I use background images.
I don´t want my images to be stretched or deformed when I run my application on different screens with different ratios.
I already have different images for different screen sizes.
Can someone please explain to me how Android Studio handles the image sizes.
How can I make it that the image isn´t streched, but a sector that fits the screen is being displayed?
Android System uses resource qualifiers/filters to load different resources based on current screen configuration.
Now you have different images for different screen sizes, Good!!
the Folder structure would be something like this.
res
-drawable-mdpi
-drawable-hdpi
-drawable-xhdpi
-drawable-xxhdpi
Now when you run your Application on a device with mdpi screen, android loads images which are under drawable-mdpi folder, and when you run your application on a device with screen density of xhdpi android loads images from drawable-xhdpi folder.
Instead of setting the image as a background for my layout I created an image view. There I set the scale Type to centerCrop and it had the wanted effect!

Android, my app looks good on vertical screens, but size is all distorted on tablets (wide screen)

When my android app gets drawn on a tablet or a emulator that has a wide screen (wasvga,wxcage800 and my tablet) it draws the graphic images from the drawblw-ldpi folder (low res) instead of the drawl-hdpi folder. I'm curtly using a bitmap button. They are all very small (since the smallest image is being drawn) on the tables, but the correct image gets drawn on all the vertical screens.
Why is this????
Is there a way to fix it????
The default folder is the mdpi folder. If another folder doesn't exist, or doesn't have your image, android gets it from drawable-mdpi. Put your images there, and let us know if it works.

Android Screen Size resources

I am trying to understand screen sizes and densities and what I really need to do in order to make my multiple choice question game work on every Android screen nicely. I want my game to look the same in every screen size and density meaning no changes to the layout and good looking images.
Basically my game displays questions which are png files, and answers to choose from which are also png files. I specify each imageview size and imagebutton in dp, and the locations of these on the screen in dp. For my layout background image I just have it fill parent width and height.
So my question is why can't I just have one drawable folder with hdpi images? Therefore, the images would be scaled appropriately in dp on all screen sizes and located in the same place and look the same on every screen. And the images would look good on hdpi screens and smaller ones? Also, why can't I just have one layout folder with the same explanation?for your answers!
You can create the only one folder but the images in that must be .9.png bcoz these images stretched according to the screen. Another way is create the different size images and place them in the hdpi,mdpi,ldpi folders.
You can create only one folder for both ressources. But for image, if you dont want to get uggly stretched image you should create 3 image size with different dpi for each folder. Your picture will be sharper for hight dpi screen and faster for low dpi screen with a picture near the final size.

in which folder put image for setting to background of layout android

i am putting the image in three of the drawable,drawable-hdpi and drawable-ldpi for supporting all type of screen but when i see the output of background image in 240*320 screen resolution the background image is not as clear as origional so my question is where to, means in which folder i put the background image for supporting it all type of screen size and density, maens then my image should not distorted or bluer...
i am using the background image of size:320*480
thanks
make one folder name
drawable-nodpi
put your image in that and use it and dont keep that image in other folders.
the image will not be scaled or stretched.
Anoher Way
the best way is to make 3 different size images and put int drawable-ldpi(240X320),drawable-mdpi(320X480),drawable-hdpi(480X800) folder with the same name.
TO LEARN MORE PLEASE VISIT THIS LINK.
Supporting Multiple SCreens
You can put different same image in drawable-hdpi,mdpi and ldpi.Depending on the density of devices they will take the images from the corresponding folder.
With different devices you should have same image but with different size and density.for You can search in internet the specifications of devices.If density is less than 160 then put image in ldpi,if 160 then use mdpi and if 240 or above use hdpi.Also change the size of image to the screen size of corresponding device.Hope it will help.

Categories

Resources