for (int x = 0; x < canvas.getHeight(); x += LINE_SPACING) {
canvas.drawLine(0, 0, 0, canvas.getWidth(), paint);
此代码制作一条垂直线。我怎样才能使这个水平
for (int x = 0; x < canvas.getHeight(); x += LINE_SPACING) {
canvas.drawLine(0, 0, 0, canvas.getWidth(), paint);
此代码制作一条垂直线。我怎样才能使这个水平
您将 x 和 y 的概念颠倒过来:
canvas.drawLine(0, 0, canvas.getWidth(), 0, paint);
此外,目前还不清楚为什么你有这个循环。如果你想画一堆水平线,它应该是这样的:
for (int y = 0; y < canvas.getHeight(); y += LINE_SPACING) {
canvas.drawLine(0, y, canvas.getWidth(), y, paint);
}
for (int y = 0; y < canvas.getWidth(); y += LINE_SPACING) {
canvas.drawLine(0, 0, canvas.getHeight(), 0, paint);