Question

I'm working with the 1.6 version of the ZXing barcode scanner code.

Although the version of this app from the Android Market (3.53) runs fine on my Incredible, the ViewFinderView looks wrong when I compile it myself (3.5beta).

I have found that the default canvas size of the ViewFinderView (which fills the entire screen) is 533x320, while the actual screen dimensions are 800x480.

So in the onDraw method, the ViewFinderView is assuming screen coordinates for the viewfinder rectangle, but applying them in the canvas coordinates of onDraw. This results in the viewfinder getting drawn too far and too big in the x and y dimensions.

So what determines that actual dimensions of the canvas your View gets? In my case, the canvas is scaled down by a third compared to screen coordinates. I can't find any differences in the code that might affect this between versions 3.5beta and 3.53.

Was it helpful?

Solution

I believe the application doesn't declare support for screens with varying density. There is a tag called <supports-screens> in AndroidManifest.xml and it has a parameter anyDensity. If set to true, it is assumed that application can handle screens with different densities, if set to false, Android scales the screen itself so the app may draw to the screen of a different size than the actual depending on the screen density.

By default this parameter is set to true if the application targets API Level of 4 and higher and to false otherwise. This is done because before Android 1.6 applications were made for a fixed screen size and density, and starting with Android 1.6 this changed, so backwards compability had to be maintained.

In your case the screen has high density, which corresponds to a 1.5 coefficient. So if you draw to a screen with the height of 800 px, this is considered the same as drawing to the screen of 533 px with normal density.

If you want the Canvas to have the "real" size, anyDensity has to be set to true or at least minSdkVersion to 4 and higher.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top