1 protected void onDraw(Canvas canvas) { 2 int count = getLineCount(); // method entends from TextView. 3 Rect r = mRect; 4 Paint paint = mPaint; 5 6 //第一次画第一条线。以后每次输入,换行时仍然检测,继续画线 7 for (int i = 0; i < count; i++) { 8 int baseline = getLineBounds(i, r); 9 baseline += outY; 10 //添加一个固定值outY,使画线向下平移一定高度,这样光标就不会压线了 11 canvas.drawLine(0, baseline + 1, r.right, baseline + 1, paint); 12 } 13 14 //根据判定条件,画出固定条数的线 15 if(count < linecount){ 16 for (int j = count; j < linecount; j++) { 17 float baseline = basicline + outY + j*linedistance; 18 canvas.drawLine(0, baseline + 1, r.right, baseline + 1, paint); 19 //get lineHeight 可以使用getLineHeight(); 20 } 21 } 22 super.onDraw(canvas); 23 }