0
我有這段代碼。 只有第一個drawLine被繪製,其餘2個不是。任何人都可以解釋爲什麼另外兩條曲線在目前的情況下不起作用嗎? 如果在drawLine()語句中將「factor」替換爲「1/2」,它們將起作用。 由於在Canvas.drawLine()中使用常量
公共類的RenderView延伸查看{
Paint paint;
private float factor = 1/2;
public RenderView(Context context) {
// TODO Auto-generated constructor stub
super(context);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
}
@Override
protected void onDraw(Canvas canvas) {
int screenWidth = canvas.getWidth();
int screenHeight = canvas.getHeight();
paint.setColor(Color.RED);
canvas.drawLine(0, 0, screenWidth, screenHeight, paint);
canvas.drawLine(factor*screenWidth, 0, factor*screenWidth, screenHeight, paint);
canvas.drawLine(0, factor*screenHeight, screenWidth, factor*screenHeight, paint);
invalidate();
}
}