I am trying to draw a grid for a game but my lines are offset from where I want them. I have tried adding a fixed offset but I want it to be scaleable on difference devices.
Here is the code for creating the path the View will draw:
float top = getPaddingTop() + getTop();
float bot = getBottom() - getPaddingBottom();
float left = getLeft() + getPaddingLeft();
float right = getRight() - getPaddingRight();
float squareWidth = (right - left) / 10;
float squareHeight = (bot - top) / 10;
gridPath.moveTo(left, top);
gridPath.lineTo(left, bot);
gridPath.lineTo(right, bot);
gridPath.lineTo(right, top);
gridPath.close();
for (int i = 1; i < 10; i++) {
gridPath.moveTo(squareWidth * i, top);
gridPath.lineTo(squareWidth * i, bot);
}
for (int i = 1; i < 10; i++){
gridPath.moveTo(left, squareHeight * i);
gridPath.lineTo(right, squareHeight * i);
}
gridPath.close();
I want an evenly drawn grid but I get this:
Is there something I am missing?