什么决定了视图中的初始 Canvas 尺寸?
我正在使用 1.6 版本的 ZXing 条形码扫描仪代码。
尽管 Android Market 上的这个应用程序版本 (3.53) 在我的 Incredible 上运行良好,但当我自己编译它时 (3.5beta),ViewFinderView 看起来错误。
我发现 ViewFinderView 的默认画布尺寸(填满整个屏幕)是 533x320,而实际屏幕尺寸是 800x480。
因此,在 onDraw 方法中,ViewFinderView 假设取景器矩形的屏幕坐标,但将它们应用到 onDraw 的画布坐标中。这会导致取景器在 x 和 y 维度上绘制得太远且太大。
那么什么决定了视图获得的画布的实际尺寸呢?就我而言,与屏幕坐标相比,画布缩小了三分之一。我在 3.5beta 和 3.53 版本之间找不到任何可能影响此问题的代码差异。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信该应用程序没有声明支持不同密度的屏幕。 AndroidManifest.xml 中有一个名为
的标签,它有一个参数anyDensity
。如果设置为 true,则假定应用程序可以处理不同密度的屏幕,如果设置为 false,Android 会自行缩放屏幕,以便应用程序可以绘制到不同密度的屏幕根据屏幕密度,与实际尺寸不同。默认情况下,如果应用程序的目标 API 级别为 4 或更高,则此参数设置为
true
,否则设置为false
。这样做是因为在 Android 1.6 应用程序是针对固定的屏幕尺寸和密度制作的,而从 Android 1.6 开始,这种情况发生了变化,因此必须保持向后兼容性。在您的情况下,屏幕具有高密度,对应于 1.5 系数。因此,如果您绘制到高度为 800 px 的屏幕,则这被认为与绘制到正常密度的 533 px 屏幕相同。
如果您希望 Canvas 具有“真实”大小,则必须将anyDensity 设置为 true 或至少设置为 minSdkVersion代码> 到 4 及更高。
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 parameteranyDensity
. If set totrue
, it is assumed that application can handle screens with different densities, if set tofalse
, 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 tofalse
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 totrue
or at leastminSdkVersion
to 4 and higher.