Android menu icons scaling issue - android

I am using the onCreateOptionsMenu method to create a toolbar with icons in the MainActivity of my app. I am testing on different screen sizes and pixel densities with Android Studio's emulator. The documentation states, "Based on the density of the current screen, the system uses any density-specific resources from your app. If resources are not available in the correct density, the system loads the default resources and scales them up or down as needed." I've tried putting all of my vector icons the default drawable directory, but the system does not scale them for different screen sizes or densities at all. Nor does onCreateOptionsMenu scale the height of the toolbar or the title text. Is it supposed to? Because of this, I have also tried using different density buckets to address that problem. However, I'm running into an issue with greatly varying screen sizes sharing the same density bucket.
As an example, I'm testing on Pixel 3 (5.5" phone) and Pixel C (10" tablet). They are using the same density bucket (xhdpi) so if I use a 24dp x 24dp icon for the phone, then it looks way too small on the tablet. How do I work around this?

You can string together multiple qualifiers and create a custom bucket. So in addition to the drawable-xhdpi bucket I added a drawable-sw720dp-xhdpi bucket with larger icons for the 10" tablet. Now tablet displays the slightly larger icons while the phone still uses the standard bucket. The solution can be found in the comments of the selected answer in this post by #Theo. Unfortunately the documentation does not state that multiple qualifiers are supported.

Related

Does Mipmap scale up or scale down?

I was researching a little bit on mipmap to learn more about it. However, I just ended up confusing myself even more.
In this post: Mipmaps vs. drawable folders
The reason they use a different density is that some launchers
actually display the icons larger than they were intended. Because of
this, they use the next size up.
Hence, I got the idea that with larger icons mipmap will use a higher density(scaling up).
But then in this post: Mipmap drawables for icons
However some launchers (shipped with some devices, or available on the
Play Store) use larger icon sizes than the standard 48dp. Launchers
use getDrawableForDensity and scale down if needed, rather than up, so
the icons are high quality. For example on an hdpi tablet the launcher
might load the xhdpi icon.
I concluded that for larger icons, mipmap will scale down the icons to provide higher quality.
And finally in this post:Mipmap drawables for icons by #Sergej:
What Android will do is, it will try to pick up the image from a
higher density bucket instead of scaling it up. This will increase
sharpness (quality) of the image.
Mipmap will use a higher density instead of scaling up for larger icons.
What is really going on? Thanks.
Update:
Also, in the second post Mipmap drawables for icons by #Kazuaki, I don't understand this
Different home screen launcher apps on different devices show app
launcher icons at various resolutions. When app resource optimization
techniques remove resources for unused screen densities, launcher
icons can wind up looking fuzzy because the launcher app has to
upscale a lower-resolution icon for display. To avoid these display
issues, apps should use the mipmap/ resource folders for launcher
icons. The Android system preserves these resources regardless of
density stripping, and ensures that launcher apps can pick icons with
the best resolution for display.
Even if unused screen densities are stripped, why would the launcher app have to switch to a lower resolution? The current resolution(whatever resolution it's using), isn't unused, meaning, it wouldn't be stripped and the launcher icon wouldn't have to switch resolutions.
How does this work? Thanks.
I think your confusion about #Kazuaki quote is the now deleted documentation, replaced by: https://developer.android.com/training/multiscreen/screendensities#mipmap
Like all other bitmap assets, you need to provide density-specific versions of you app icon. However, some app launchers display your app icon as much as 25% larger than what's called for by the device's density bucket.
For example, if a device's density bucket is xxhdpi and the largest app icon you provide is in drawable-xxhdpi, the launcher app scales up this icon, and that makes it appear less crisp. So you should provide an even higher density launcher icon in the mipmap-xxxhdpi directory. Now the launcher can use the xxxhdpi asset instead.
The mipmap directories provide that "do not remove when trying to make a smaller APK".
In my understanding, mipmaping is principally for scaling-down.
In OpenGL, you can set texture filtering modes. One for scaling-down (minification), another for scaling-up (magnification) (cf. An Introduction to Texture Filtering).
Scaling-down (GL_TEXTURE_MIN_FILTER):
GL_NEAREST
GL_LINEAR
GL_NEAREST_MIPMAP_NEAREST
GL_NEAREST_MIPMAP_LINEAR
GL_LINEAR_MIPMAP_NEAREST
GL_LINEAR_MIPMAP_LINEAR
Scaling-up (GL_TEXTURE_MAG_FILTER):
GL_NEAREST
GL_LINEAR
You notice that there are no options of mipmap for scaling-up, but those are for scaling-down.
So, in my understanding, if scaling-up/down is needed, the nearest higher density texture is chosen to scale-down. Only when the current magnification is higher than the highest density texture, scaling-up is done based on the highest one.

Android multi Screen Support

I know that for supporting different screen size we use layout,layout-large,layout-xlarge folder , but i have confusion regarding drawable folder,by default they are ,
1. drawable-ldpi For low density screens
2. drawable-mdpi For medium density screens
3. drawable-hdpi For high resolution screens
4. drawable-xhdpi For extra high resolution screens
But A simple approch is
1.Drawable
2.Drawable-large
3.Drawable-xlarge
is it ok to go with this approch?
Google changed layout system after API 13 (Android 3) so both of them works but it's recommended to use dpi system which related to screen density but old system was realted to screen sizes which might make problems with large screen devices with low dpi screen density
It is better to use screen density folders because (quoting the Android doc)
Maintaining density independence is important because, without it, a UI element
(such as a button) appears physically larger on a low density screen and smaller
on a high density screen. Such density-related size changes can cause problems in
your application layout and usability.
So using density-pixels Android scales your widgets (Buttons, ImageViews, etc) by itself relating your Activity and the Drawables you need to the appropiate res folder. In fact, you should be using this density system in your Layouts too (layout-mdpi, layout-hdpi, etc).

android tablet icon sizes

I have created four versions of my launcher icon for ldpi, mdpi, hdpi and xhdpi devices. They are of dimensions 36x36, 48x48, 72x72 and 96x96.
I'm wondering what will happen when using a large screen. Consdering large screens are rouglhy 7" + in size a ldpi, large screen will surely not want a 32x32 icon image, located in a drawable-ldpi folder.
I cannot find anything on the dev guide that indicates what icon sizes to assign to large and xlarge devices. Presumably I would put a larger copy of the icon in the drawable-large and drawable-xlarge folder. However, I do not know what sizes to use. Does anyone have any recommendations?
Google provide an online tool called Android Assest Studio which creates the launcher icons in the correct size for you. http://android-ui-utils.googlecode.com/hg/asset-studio/dist/icons-launcher.html
A 7-10" tablet doesn't need anything unusually large. You don't need anything bigger than a 96x96 launcher icon for this use case. There is a table in the Launcher Icons section of the design docs that shows which sizes correspond to which densities.
Have a look at the Declaring Tablet Layouts section of the design docs for more info on how to organize resources for 7-10" screens. (Note that the resource used will depend on the screen density, it is possible that a 7" tablet will have an mdpi screen.)

Supporting Multiple resolution devices Android

I am stuck in a situation.
I created an application for Samsung Galaxy Tab 7". The same application when i run on the HTC Flyer it shows very small fonts.
I tried following :
I thought may be the screen of HTC Flyer is xhdmi so i crated folders accordingly
res -> values-large-xhdmi -> styles.xml -> <item textsize>20</item>
res -> values-large-> styles.xml -> <item textsize>16</item>
this is not working.. :(
any help will be highly appreciable in this regard.
Thanks.
Check out this recent blog post on sizes: http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html
A typical 7” tablet has a 1024x600 mdpi screen. This also counts as a
large screen.
The original Samsung Galaxy Tab is an interesting case. Physically it
is a 1024x600 7” screen and thus classified as “large”. However the
device configures its screen as hdpi, which means after applying the
appropriate ⅔ scaling factor the actual space on the screen is 682dp x
400dp. This actually moves it out of the “large” bucket and into a
“normal” screen size. The Tab actually reports that it is “large”;
this was a mistake in the framework’s computation of the size for that
device that we made. Today no devices should ship like this.
So you need to think of the Galaxy as a large sized screen but with hdpi.
THe HTC Flyer will be large sized screen but with mdpi.
When specifying sizes you need to stick with dp, as this normalizes all sizes to scale appropriately for the different density screens. Use a dimension to specify in a xml value resource.
As milind hinted (i think), it is probably better to use the same style for these two screen sizes and specify a dimen resource. This resource can then be customized for the different displays.
The bottom line, however, is that you are using text size differences based on the screen size. The text size should be indicated in dp, so it will scale accordingly to any screen density. Really, the only resources that should be based on screen size are layouts.
If you are plan to make Multiple resolution Supporting android application just you have care about image and xml no other needs that you have same images with three different size putting in different folders like drawable-hdpi, drawable-ldpi, drawable-mdpi. you can make style.xml common for all.
Thanks

how to get same sized launcher icons on different emulator skins…(android)

have a look at figure 2. in the link given below.. http://developer.android.com/guide/practices/screens_support.html..
there it is being mentioned that ,The platform provides density independence to applications by default.(launcher icons are displayed at the same physical sizes, although screen sizes, aspect ratios, and densities are different.)
and showed with 3 emulator screens namely WVGA high density (left), HVGA medium density (center), and QVGA low density (right)...
i have created these 3 avd's and tested but the launcher icons are different in different emulator..can any one knows why it so and how should i get same sized launcher icons on those emulators...
you should refer this:
http://developer.android.com/guide/practices/ui_guidelines/icon_design.html
you have 3 different drawable folder name drawable-mdpi/,drawable-hdpi, drawable-ldpi/ in your res/ folder and each of them have different size icon. if you want same size icon in each emulator then put the same size icon in all three folders.
Keep in mind that your monitor is of a fixed pixel density, while these various devices will have differing pixel density. That means the same number of pixels will be a different physical size on your monitor than it will be on an Android device (which will typically have much smaller pixels than your monitor).

Categories

Resources