我在android设备的AR视图中绘制星座线。使用以下代码。开始时,AR视图中对象的响应速度是可以的。关闭AR视图或离开AR视图后,重新打开或返回AR视图。 AR视图中对象(星座)的响应速度变慢(可能需要1秒)。如何处理这个问题并加快速度。 lenght1 = 352,length2 = 384.如何提高性能。
顺便说一句,在我卸载应用程序并再次运行应用程序后,AR视图中对象的响应速度变为正常。
private void drawConstellationLine(Canvas canvas, int displayHeight,
int displayWidth) {
int length;
float ex = 0, ey = 0, bx = 0, by = 0;
Paint pline = new Paint();
pline.setColor(Color.RED);
double time1 = System.currentTimeMillis();
int i,j,length1,length2;
for( i = 0, length1 = ShowMoon.starlinelist.size(); i<length1;i++)
{
for( j = 0, length2 = ShowMoon.starlist.size(); j<length2;j++){
//System.out.println("length2:"+length2);
if(ShowMoon.starlinelist.get(i).beginhr ==ShowMoon.starlist.get(j).hr) {
bx = (float)ShowMoon.starlist.get(j).x;
by = (float)ShowMoon.starlist.get(j).y;
}
if(ShowMoon.starlinelist.get(i).endhr ==ShowMoon.starlist.get(j).hr) {
ex = (float)ShowMoon.starlist.get(j).x;
ey = (float)ShowMoon.starlist.get(j).y;
}
}
if (((bx >= 0 && bx <=displayWidth) ||( ex >= 0 && ex <= displayWidth))
&& ((ey >= 0 && ey <=displayHeight) || (by >= 0 && by <= displayHeight))){
canvas.drawLine(bx, by, ex, ey, pline);
//
double time2 = System.currentTimeMillis();
System.out.println("time dif:"+(time2-time1));
}
}
这两个代码:if(ShowMoon.starlinelist.get(i).beginhr == ShowMoon.starlist.get(j).hr)。 if(ShowMoon.starlinelist.get(i).endhr == ShowMoon.starlist.get(j).hr) 花了很多时间。