1

我用圆、弧和线在画布上画了一个基本的史密斯圆图。我已经在许多大小的模拟器屏幕上运行了该应用程序,并且一切都运行良好,但是一旦我在实际设备(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);

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

4

1 回答 1

0

您必须使用百分比值而不是数字...此外,请尝试查看从 getwidth() 获得的值的转换。可能缺少一些值..

于 2012-12-24T18:42:01.877 回答