我有两个方法,1个注册值,它看起来像这样:
public void setCordinates(float x, float y, float x2, float y2){
String str = new String();
str = "DETAILS. X Value: "+x+". Y Value: "+y;
Log.d("DETAILZZZ", str);
str = "DETAILS2222 X Value: "+x2+". Y Value: "+y2;
Log.d("DETAILZZZ2",str);
this.x1=(x);
this.x2=(x2);
this.y1=(y);
this.y2=(y2);
str = "DETAILS. X Value: "+this.x1+". Y Value: "+this.y1;
Log.d("DETAILZZZ", str);
str = "DETAILS2222 X Value: "+this.x2+". Y Value: "+this.y2;
Log.d("DETAILZZZ2",str);
}
在这个参数中,我目前传递X值:180.0。 Y值:140.0和X值:520.0。 Y值:450.0
当我在上面的方法中打印出来时,logcat给了我正确的值:这是logcat:
D/DETAILZZZ2﹕ DETAILS2222 X Value: 520.0. Y Value: 450.0
D/DETAILZZZ﹕ DETAILS. X Value: 180.0. Y Value: 140.0
但是在我需要使用这个值的其他方法中,logcat将这些变量显示为零,这里是代码。
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
String str = new String();
super.onDraw(canvas);
mFinalbitmap = BitmapFactory.decodeResource(getResources(), R.drawable.planr);
mFinalbitmap = Bitmap.createScaledBitmap(mFinalbitmap, getWidth(), getHeight(), true);
paint.setStyle(Paint.Style.STROKE);
str = "DETAILS----------Width: "+getWidth()+". Heigth: "+getHeight()+". X Value: "+this.x1+". Y Value: "+this.y1;
Log.d("DETAILZZZ", str);
str = "DETAILS2222----------Width: "+getWidth()+". Heigth: "+getHeight()+". X Value: "+x2+". Y Value: "+y2;
Log.d("DETAILZZZ2", str);
this.x1=((getWidth()/599f)*x1);
this.x2=((getWidth()/599f)*x2);
this.y1=((getHeight()/740f)*y1);
this.y2=((getHeight()/740f)*y2);
canvas.drawBitmap(mFinalbitmap, 0, 0, null);
canvas.drawCircle(x1, y1, 30, paint);
canvas.drawCircle(x2, y2, 30, paint);
}
Logcat给出了这个:
DETAILS----------Width: 1080. Heigth: 1533. X Value: 0.0. Y Value: 0.0
D/DETAILZZZ2﹕ DETAILS2222----------Width: 1080. Heigth: 1533. X Value: 0.0. Y Value: 0.0
编辑:不需要完整代码,不提供任何有用的信息。