나는이 링크에 참조 : How do I make a dotted/dashed line in Android?, DashPathEffect
을 사용했습니다. 그러나 이것은 나를 위해 작동하지 않습니다? 왜? 내 코드 :android, edittext에서 점선을 그리는 방법
public class NoteEditText extends EditText {
private Paint mPaint;
public NoteEditText(Context context) {
super(context);
}
public NoteEditText(Context context, AttributeSet attrs) {
super(context, attrs);
mPaint = new Paint();
mPaint.setStrokeWidth(1);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setColor(Color.DKGRAY);
PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1);
mPaint.setPathEffect(effects);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
int height = this.getHeight();
int lineHeight = this.getLineHeight();
int lineNum = height/lineHeight;
L.l("line count: " + lineNum);
for (int i = 0; i < lineNum; i++) {
int y = (i + 1) * lineHeight;
canvas.drawLine(0, y, this.getWidth() - 1, y, mPaint);
}
}
}