图表在模拟器上绘图很好但在手机上没有

时间:2012-12-24 18:09:03

标签: android drawing android-canvas

我使用圆圈,圆弧和直线在画布上画了一张基本的史密斯圆图。我已经在众多大小的模拟器屏幕上运行应用程序并且所有工作都很完美但是一旦我在实际设备(Android级别2​​.3.5)上尝试它,图表就不会排列,因为它应该是一些对象不合适。

在编写代码时,我小心地使用get.Width()和get.Height()作为参数,而不是使用像素,以便应用程序可以在所有设备上正常工作。以下是我使用的代码示例:

canvas.drawCircle(canvas.getWidth()*1/2, canvas.getHeight()*3/8, canvas.getWidth()*475/1000, black);
        canvas.drawCircle(canvas.getWidth()*5/8, canvas.getWidth()*5/8, canvas.getWidth()*349/1000, black);
        canvas.drawCircle(canvas.getWidth()*6/8, canvas.getWidth()*5/8, canvas.getWidth()*228/1000, black);
        canvas.drawCircle(canvas.getWidth()*7/8, canvas.getWidth()*5/8, canvas.getWidth()*103/1000, black);
arc0.set(canvas.getWidth()/2, canvas.getHeight()*-139/700, canvas.getWidth()*100/69, canvas.getHeight()*3/8);   
        arc1.set(canvas.getWidth()*-6/112, canvas.getHeight()*-80/100, canvas.getWidth()*195/100, canvas.getHeight()*72/192);   
        arc2.set(canvas.getWidth()*7/10, canvas.getHeight()*70/700, canvas.getWidth()*125/100, canvas.getHeight()*3/8); 
        arc3.set(canvas.getWidth()/2, canvas.getHeight()*3/8, canvas.getWidth()*100/69, canvas.getHeight()*91/96);
        arc4.set(canvas.getWidth()*-8/112, canvas.getHeight()*3/8, canvas.getWidth()*195/100, canvas.getHeight()*150/100);
        arc5.set(canvas.getWidth()*7/10, canvas.getHeight()*3/8, canvas.getWidth()*125/100, canvas.getHeight()*65/100);

图表在我尝试过的所有不同尺寸的仿真器屏幕上都很好,所以任何人都可以告诉我它为什么没有在实际设备上排队。感谢

1 个答案:

答案 0 :(得分:0)

你必须使用百分比值而不是数字...此外,请尝试查看来自getwidth()的值的转换。可能有些价值观缺失......