如何解决Android自定义EditText行间距
我使用以下代码自定义了EditText,以在每行下方绘制一条线,就像笔记本一样:
public class LinedEditText extends androidx.appcompat.widget.AppCompatEditText {
private Rect mRect;
private Paint mPaint;
// we need this constructor for LayoutInflater
public LinedEditText(Context context,AttributeSet attrs) {
super(context,attrs);
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(context.getResources().getColor(R.color.notebookLineColor));
mPaint.setStrokeWidth(3.0f);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
setLineSpacing(100,3f);
}
}
@Override
protected void onDraw(Canvas canvas) {
int count = getLineCount();
Rect r = mRect;
Paint paint = mPaint;
for (int i = 0; i < count; i++) {
int baseline = getLineBounds(i,r);
canvas.drawLine(r.left,baseline + 1,r.right,paint);
}
super.onDraw(canvas);
}
}
现在我正在尝试增加每行之间的间距,但是使用lineSpacingExtra
和lineSpacingMultiplier
属性不起作用。
有人可以告诉我增加行距的方法吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。