Going over this SO answer Android: Ruled/horizonal lines in Textview and some code from the book that I am reading, I came up with this:
@Override
public void onDraw(Canvas canvas){
// color the paper
canvas.drawColor(paperColor);
// draw ruled lines
int lineCount = getLineCount();
Rect r = rect;
for(int i = 0; i < lineCount; i++){
int baseLine = getLineBounds(i, r);
canvas.drawLine(r.left, baseLine+1, r.right, baseLine+1, linePaint);
}
// draw margin
canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint);
// move the text across the margin
canvas.save();
canvas.translate(margin, 0);
// render the text
super.onDraw(canvas);
canvas.restore();
}
However, though, I only get ruled lines if I add more lines of text to the EditText
. This is because getLineCount()
has been used. Basically, I want the EditText
to look like a page from a notebook.
What modification to the code is needed?