我有这个代码。只有第一个 drawLine 被绘制,其余 2 个不被绘制。谁能解释为什么其他两条拉线在本案中不起作用?如果我在 drawLine() 语句中将“因子”替换为“1/2”,它们就会起作用。谢谢
公共类 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();
}
}