我一直试图在Android中绘制多个圈子,但它不会工作,我看不出我做错了什么。当我运行它时,一个圆圈工作得很好。我试图找到类似的问题,但我发现的问题似乎比我想要的这个简单的应用程序更先进一些。绘制多个圈子Android
public class DrawCharsActivity extends Activity {
Paint[] paint;
double lon = 30;
double lat = 20;
int scrWidth;
int scrHeight;
int x;
int y;
//String latitudeString[] = new String[]{"30", "20"};
//String longitudeString[]= new String[]{"30", "20"};
String name[] = new String[]{"joseph", "jj"};
Double longitude[] = new Double[]{30.2, 30.2};
Double latitude[] =new Double[]{30.2, 45.2};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(new Panel(this));
// x = (int) ((scrWidth/360.0) * (180 + lon));
//y = (int) ((scrHeight/180.0) * (90 - lat));
scrWidth = getWindowManager().getDefaultDisplay().getWidth();
scrHeight = getWindowManager().getDefaultDisplay().getHeight();
}
class Panel extends View {
public Panel(Context context) {
super(context);
}
@Override
public void onDraw(Canvas canvas) {
for (int i = 0; i < name.length; i++) {
paint = new Paint[i];
paint[i].setColor(Color.BLACK);
paint[i].setStrokeWidth(1);
paint[i].setTextSize(20);
//longitude[i] = Double.parseDouble(latitudeString[i]);
//latitude[i] = Double.parseDouble(longitudeString[i]);
x = (int) ((scrWidth/360.0) * (180 + longitude[i]));
y = (int) ((scrHeight/180.0) * (90 - latitude[i]));
canvas.drawColor(Color.WHITE);
canvas.drawCircle(x, y, 3, paint[i]);
System.out.println(x + "x" + name[i]);
System.out.println(y + "y" + name[i]);
}
// canvas.drawLine(80, 80, 80, 200, paint);
// canvas.drawText(""+canvas.getWidth()+", "+canvas.getHeight(), 0,
// 200,paint);
}
}
}
行,所以我解决了这个问题,我设置类面板 面板面板; 在我 DrawCharsActivity。 然后,而不是写 的setContentView(新面板(本)); 我写 面板=新面板(本); panel.setBackgroundColor(Color.WHITE); setContentView(panel); 感谢您的回复El_Mochuq,感谢您的努力。谢谢! –