开发者

How to create lines in a textview?

开发者 https://www.devze.com 2023-04-12 18:58 出处:网络
I am 开发者_JAVA技巧creating a textview which looks similar to a page of notebook.So how could I create Lines in a textview? Someone could help??You can use the notepad example but specifically look a

I am 开发者_JAVA技巧creating a textview which looks similar to a page of notebook.So how could I create Lines in a textview? Someone could help??


You can use the notepad example but specifically look at the the NoteEditor.java the LineEditText class

public static class LinedEditText extends EditText {
    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.STROKE);
        mPaint.setColor(0x800000FF);
    }

    @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, baseline + 1, paint);
        }

        super.onDraw(canvas);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消