I know many persons have asked this question, but I really can't get a clear answer. I am new to android, and find it's hard to have my layout work well on all different size devices.Below is the problem:(I put the sprite image in drawable-hdpi folder).
On mdpi device with resolution 320*480,the screen looks like this:
on hdpi device with resolution 480*800, the screen looks like this:
both images above looks good, but when on mdpi device with resolution 480*800, the screen is looks bad like this:
Could you please tell me how to solve this problem? I can't understand why it's mdpi device when its resolution is 480*800?
You should always provide bitmap resources that are properly scaled to each of the generalized density buckets: low, medium, high and extra-high density. This helps you achieve good graphical quality and performance on all screen densities.
To generate these images, you should start with your raw resource in vector format and generate the images for each density using the following size scale:
xhdpi: 2.0
hdpi: 1.5
mdpi: 1.0 (baseline)
ldpi: 0.75
This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.
refer this link :
http://developer.android.com/training/basics/supporting-devices/screens.html
and add this to your manifest
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
Related
I was working on android app based on phone. However, recently the app need to support the tablet.
The design was based on 1920 * 1080, I put all images/ icons into the xxhdpi folder and for lower resolution I just let android to help me rescale it.
The problem is , it works well on phone(1280 * 800 5"), but when I use tablet to check it (say , galaxy tab 2 which resolution is only 1280 * 800 10.1" and 1024 * 600) but it looks like very blur . How to fix it ? Thanks for helping.
Added
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:normalScreens="true"
android:anyDensity="true"/>
already but still the same
Update: I also find that the dp is too small for the tablet
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
<item name="android:actionBarSize">60dp</item>
</style>
I was using a custom actionBarSize , it works nice on phone, but the 60dp is too small for tablet, how can I fix it as well? Thanks
Well, I don't think you following the guidelines when you're using images. The android documentation doesn't say anything about screen resolutions when dealing with images, it rather focuses on pixel density when referring image resources (usually drawables) which is explained here. Remember that you can have two types of images (as far as I know):
Image resources (usually drawables)
Image assets
When using drawables you have to focus on pixel density rather than screen resolution because as you have just found out a small (or regular) screen device can have exactly the same resolution as a large screen device, to top it off, sometimes a normal screen device (handset) can have a higher resolution than a large screen device (tablet) where obviously in this case the handset has a much higher pixel density. So, you need to follow their guidelines take a medium pixel density (mdpi) device as the baseline to design your image resources as follows...taking a 96px image as an example...
for a medium density device (mdpi) provide an image with 96px in the drawable folder...this is your baseline
then, target a high pixel density(hdpi) device by multiplying your baseline image by 1.5...that is, 96x1.5 = 144px...place this image inside the drawable-hdpi folder with exactly the same name
a x-large pixel density device image would be the baseline image multiplied by 2 (96x2=192px). This goes inside the drawable-xhdpi folder
for an xx-large picel density (xxhdpi) device multiply the baseline image by 3 (96x3=288) and place it inside the drawable-xxhdpi folder
Notice in the link provided that you don't need to provide an image for a device with a low pixel density since Android scales it down from mdpi without any problems...
Note: Android also supports low-density (LDPI) screens, but you normally don't need to create custom assets at this size because Android effectively down-scales your HDPI assets by 1/2 to match the expected size.
In your case, whats happening is that your Galaxy tablet has a lower pixel density and Android down-scales the image from a xxhdpi to whatever density the tablet has (hdpi or xhdpi)....so, it your image is a 512px image Android would down-scale it to 341px for xhdpi or 256px for an hdpi device.
If you follow these guidelines and focus on pixel density, you should be fine. However, for images in the assets folder there's no much you can do apart from using the ScaleType enum or using stretchable 9-patch images
Hope this helps
Update
Actually, according to this link, the Galaxy Tab 2 has mdpi screen, which means your image will be scale down three times from xxhdpi. You should provide the same images with different sizes inside the appropriate drawable-x folders
I know its a way too late but recently I faced the same issue about the way app launcher icons looks on a tablet and they are blurry. I'm sure that AOS honestly chooses mdpi drawables for tablets with mdpi display density and thats the problem. So I solved this by placing smartphones icons to a tablet resources dirs as following (left column - usual smartphone drawables-density and the right - tablet dirs):
drawable-xhdpi -> drawable-large-mdpi (these are 96x96px)
drawable-xxhdpi -> drawable-large-hdpi (these are 144x144px)
drawable-xxxhdpi -> drawable-large-xhdpi (these are 192x192px)
drawable-xxxhdpi -> drawable-xlarge (these are 192x192px)
I'm not sure if last two has to be 288x288 px but since I don't have such icons in the project I guess 192x192 should be enough.
I've used several images with different sizes. I copied the images into different folders.
such as (except drawable-ldpi folder):
for example :
drawable-mdpi test.png => 60*60 px
drawable-hdpi test.png => 85*85 px
drawable-xhdpi test.png => 110*110 px
drawable-xxhdpi test.png => 110*110 px
I have only one folder my layouts:
my manifest:
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
now, when I install my project on galaxy s4, images within the program shows drawable-mdpi folder. why ?
I even made a separate folder for my layout and changed width and height of image :
res/layout/my_layout.xml imageview => layout_width and layout_height = 48*48 // default
res/layout-large/my_layout.xml
res/layout-xlarge/my_layout.xml
But always the default option is selected ! why?
you don't need to write support-screens in the minifest - default is fine.
first things first:
s4 is on the upper end of normal but it should still be normal not large. this is why your 'layout-large' was not used. but you should not use the size selection stuff, dpi selection is much better (so one layout should work).
s4 is on the edge between xxhdpi and xhdpi so samsung can decide what it is. i think they used xhdpi. but this should not realy matter.
dpi categories:
ldpi (you will not need it because neerly no device has it)
mdpi = 160dpi or 1x
hdpi = 240dpi or 1,5x
xhdpi = 320dpi or 2x
xxhdpi = 480dpi or 3x
simple dpi example:
if you have a fullscreen design/image in full hd (1080x1920) you can just cut the stuff out as you need it and will get it correct for xxhdpi. (if i remember correct - maybe xhdpi)
however, you can calculate the lower sizes from this point.
- xxhdpi = 1080x1920
- xhdpi = 720x1280 (/3*2 of the above)
- ...
if you do it this way it should work correct ;)
The android version is 2.2. And the apps will not support drawable-xhdpi with drawable-xlarge folder. However, i have met many issue when I am processing different screen size from different mobile.
The first problem is that I want to know what is the situation that android will load correct image from drawable-ldpi, drawable-mdpi, drawable-hdpi folder? There are one image in each folder (drawable-ldpi, drawable-mdpi, drawable-hdpi).
(1) 240px x 150px for drawable-ldpi
(2) 320px x 200px for drawable-mdpi
(3) 480px x 300px for drawable-hdpi
But why i cannot see correct image if the output device width screen is 480px? The output device only shown 320px width image. Not the 480px image. The issue seems that what the thing i have missing?
Then, i renamed all drawable folder to drawable-small, drawable-normal, drawable-large. It is working that drawable-large can display 480px width image. Will it be good if i do this way?
The second issue is that some samsung device have got different screen resolutions, i would like to know how to support these screen resolution as I want to make 800px width screen displays 800px width image, 900px width screen displays 900px width image? Any method can do different screen resolution? Many people said the folder drawable-xhdpi can solve issue that image can be auto-scaling. I cannot see any image can be auto-scaling. Maybe i have missing some steps.
Kindly advise.
Thanks a lot.
I will try to give you better insight into this.
Screens can be divided into more or less 4 different categories:
Low-density
medium-density (Baseline)
high-density
extra-high-density
You also get xxhdpi these days...
low-density = ldpi (120dpi)
medium-density = mdpi (160dpi)
high-density = hdpi (240dpi)
extra-high-density = xhdpi (320dpi)
Another good example comes from the android developer pages:
http://developer.android.com/images/screens_support/screens-ranges.png
You can find a list of devices and their pixel densities here:
h ttp://en.wikipedia.org/wiki/List_of_displays_by_pixel_density
h ttp://checkscreensize.appspot.com/listdevice.jsp
You will always be designing apps with multiple layouts/drawables to support different devices. Not just Samsung devices, but most brands have different devices with different pixel densities and resolutions.
In short, by providing multiple resources, android will choose the correct one to best fit the current device and if it does not find one in a certain layout or drawable folder, it will simply use the next best layout/resource with that name.
Note, this is to avoid stretching and incorrect scaling of drawables and layouts.
How to support multiple layouts ?
in your manifest file.
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Provide different layouts or drawables for different screen sizes.
Now, there are multiple ways of doing this and some ways are dependent on the sdk level.
Pre Android 3.2 / API 13 , use layout-small/normal/large/xlarge.
After Android 3.2 / API 13 , use layout-hdpi, or layout-sw600dp etc.
Here is the official table of qualifiers you can use, by placing a dash between them:
http://developer.android.com/guide/practices/screens_support.html#qualifiers
Generally, I think that you will only design for landscape mode with tablets, therefore, you could consider using only these and:
layout-ldpi
layout-mdpi
layout-hdpi
layout-xhdpi
layout-large
layout-large-land
layout-xlarge
layout-xlarge-land
and for your drawables:
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
Further, by default, I currently choose to design for 6 different devices that overall fits best in the profiles ldpi, mdpi, hdpi, xhdpi for phones (4) and tablets (2):
Samsung Galaxy S3 (720x1280, xhdpi, Normal screen size)
Samsung Galaxy S2 (480x800, hdpi, Normal screen size)
Samsung Galaxy Ace Plus (320x480, mdpi, Normal screen size)
Samsung Galaxy Mini (240x320, ldpi, Normal screen size)
Samsung Galaxy Tab 10.1 (800x1280, mdpi, X-Large screen size)
Samsung Galaxy Tab 7.0 (600x1024, hdpi, Large screen size)
Designing for these devices ensures that the app will work great on most other devices aswell.
Hope this information helped.
i have images accordingly int the hdpi and mdpi folder but when i run the application the hdpi images are loading fine on the high resolution devices but when i run on medium resolution 320 x 480 the hdpi images are loading not the medium ones. i have also tested moving the images to res/drawble but nothing happens.. please help me on this
i have set the manifest file with
<supports-screens android:smallScreens="false" android:normalScreens="true"
android:largeScreens="true" android:anyDensity="true">
<uses-sdk android:minSdkVersion="8" />
Please check if your drawable folders are correctly named.
They should be:
drawable-mdpi
drawable-hdpi
Also, be sure that your file names are identical. It works fine for me.
Sometimes it may even work to clean the project using Eclipse.
EDIT:
I think your project is working fine, but you're making some mistakes with your setup. You probably haven't read the developer guide properly: http://developer.android.com/guide/practices/screens_support.html
Anyway, what you're essentially doing is saying that mdpi = 320 x 480 and hdpi = 480 x 800 pixels. But that's not correct. The DPI (dots per inch) has nothing to do with the actual resolution of the screen. You can easily have a medium DPI screen with a resolution larger than 320 x 480 pixels.
Read the link that I posted - especially the part called "How to Test Your Application on Multiple Screens". That should help you.
On Xoom tablet i am getting density value 1.0. Is there anything i have missed in manifest file to support 3.0 or greater os devices? Below is the code snippet to print the density value on tablet.
System.out.println("******==="+getResources().getDisplayMetrics().density
+"===widht=="+getResources().getDisplayMetrics().widthPixels
+"===height=="+getResources().getDisplayMetrics().heightPixels
+"====="+getResources().getDisplayMetrics().toString());
I have also added all supported screens set to true but still getting density value wrong.
<supports-screens android:resizeable="true" android:smallScreens="true"
android:normalScreens="true" android:largeScreens="true"
android:xlargeScreens="true" android:anyDensity="true" />
Anybody have any ideas on this?
Have a look to the Android doc density:
The logical density of the display. This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), providing the baseline of the system's display. Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc.
This value does not exactly follow the real screen size (as given by xdpi and ydpi, but rather is used to scale the size of the overall UI in steps based on gross changes in the display dpi. For example, a 240x320 screen will have a density of 1 even if its width is 1.8", 1.3", etc. However, if the screen resolution is increased to 320x480 but the screen size remained 1.5"x2" then the density would be increased (probably to 1.5).