Giving Wrong Density value on Android Xoom Tablet with OS 3.1 - android

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).

Related

Multiple Screens Android

I'm developing an app in android and I have to support many different screen sizes and density. So i've created different a folder for layout : layout and layout-large.
For a normal screen size I have these drawable folders: mdpi(with a 320x480 image in it), hdpi (with a 480x800 image in it), and xhdpi (with a 640x960 image in it), but I also need a mdpi for a xlarge size screen. Should I create a drawable-large-mdpi and then put my image (480x800) in there?
Anyways I tried to do that and it seems to work just fine.
On my manifest I have:
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
I'm using three different emulators:
4.0" WVGA (480X800: hdpi),
3.2" HVGA slider (ADP1) (320x480:mdpi), and
5.1" WVGA (480X800: mdpi)
My problem is that when I run it the size of the screen never match in any of the emulators. The width seems to get a bit smaller. It is never 100%
In the AVD manager when you start your AVD manually you get Launch options, there put a check mark against scale display to real size.
Setup your monitors dpi by clicking on the question mark.
Enter the monitor screen size and monitors resolution and then click on ok.
Now enter the screen size for your emulator in inches and then click on launch.
Do the same for all three emulators your testing the app against.

how to handle android different device size

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" />

Can't disable screen compatibility mode in android

I am developing an App for all screen sizes and dpi.
The problem is that for large/smaller screen than normal the UI is being scaled, meaning I think screen compatibility mode is enabled.
This is my goal: I have an image button that is 90 pixels in height, so I think it is 90 dp in normal-mdpi device and I want it to remain 90 dp in larger and smaller screen sizes. So to the eye, the size remains the same.
The problem I am having is that is looks good (90 dp) in normal-mdpi device, but it looks much bigger and with scaling artifacts in a large-mdpi device.
I am targeting min android OS of 2.3.3, therefore I have the following manifest:
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<!--
If not set explictly, screen compatibility mode would be enabled for
large screen, which is scaling of normal
-->
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
According to the android documentation, if targeting 10 or below, you mush specify supports-screens otherwise compatibility mode is enabled by default. Problem is that I am specifying it but I am still getting the compatibility mode enabled.
Any ideas? Please let me know if my understanding is wrong.
Thanks
Ok, I figure I post an answer after a whole day of debugging.
For me, the issue seem to be the emulator. When you launch the ADV, you need to calculate the actual screen device size and know your monitor dpi so you can set it in the launch options.
Once I did this, the image button that I had specified as "x dp" in my layout and having "x pixels" in the PNG, looks the same size (in) in all screen sizes and densities.
If you would like to get rid of artifacts due to android scaling, you can provide your own images in the ldpi, hdpi, xhdpi folders with their corresponding scaling already applied.
To calculate the device screen size, use the resolution and density provided in the launch options dialog, then calculate with this formula: (looks painful but it works, you can measure with a ruler in your computer monitor and the device if x in, will be x in in your ruler)
screen size = sqrt ( (w in pixels/ dpi)^2 + (h in pixels/dpi)^2)
where w, and h is the resolution in pixels
To calculate your monitor dpi, I googled my computer type. For mac book pro 15.4 in, it is 128 and for an apple cinema display 27 in it is 109. Hope this helps.
The method I used to keep all of my images the same size is to use the regular display getWidth and getHeight methods to set a variable. Then I set my images using Bitmap.createScaledBitmap to a % of the screen size. Regardless of the dpi it will look the same. On a 240 dpi screen that is that is 16:9, to get the same image on a 480 dpi 16:9 screen would be double the dpi.
I am using these images on a canvas, but I would guess they would be similar. Also in doing animations and such it is important when not in GL. I had to redo my current game because when I played it on a lesser dpi it moved so fast it was like lightning! Moving 10 pixels on a 180 vs a 240 was an eye opener.

mdpi and hdpi images are not correctly loaded into the device android

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.

Scaling widget on Android (dp, px, screen size)

what is the best way for controlling the size of widget on Android?
Look on following table:
• On 3.6-4.0 inch screen (smartphone) with 480x800px the dpi is about 240dpi
• On 4.3 inch screen (smartphone) with 540x960px the dpi is about 270dpi
• On 7 inch screen (tablet) with 480x800px the dpi is about 130dpi
• On 7 inch screen (tablet) with 600x1024px the dpi is about 170dpi
• On 8.9 inch screen (tablet) with 1280x800/768px the dpi is about 170dpi
• On 10.1 inch screen (tablet) with 1280x800px the dpi is about 150dpi
So in general smartphones comes with much higher dpi.
Now if I create a control with 100px width it will be good on low dpi displays but bad on high, where the control will be too small. If I create the same control with 100dp it will be opposite – on high resolution displays it will scale to e.g. 150 px, but on low dpi screens (tablets) it will be still 100px or smaller is the density falls below 160dpi.
So how I should make a control that on 4inch display occupy 1inch on 7inch display occupy 1.5inch and on the 10.1inch display occupy 1inches? In other words – bigger screen size, the bigger is the control, but without considering the resolution.
But is that in fact a good approach?
Regards,
SteN
Please include this in your android manifest file..
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
and also check the following link from android developer site, this may help you in finding a rite solution for your question..
http://developer.android.com/guide/practices/screens_support.html

Categories

Resources