久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在edittext中繪制多行,例如記事本

Drawing multiple lines in edittext e.g. notepad(在edittext中繪制多行,例如記事本)
本文介紹了在edittext中繪制多行,例如記事本的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在查看 android SDK 中的記事本示例,請(qǐng)參見(jiàn)此處:http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NoteEditor.html

I was taking a look at the notepad sample in the android SDK see here: http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NoteEditor.html

問(wèn)題是它只繪制光標(biāo)所在的當(dāng)前行,例如 http://cdn2.staztic.com/screenshots/simple-notepad-app-al-1.jpg

Thing is it only draws the current line the cursor is on e.g http://cdn2.staztic.com/screenshots/simple-notepad-app-al-1.jpg

但我想顯示填滿屏幕的線條,例如http://www.itismyworld.info/wp-content/uploads/2010/03/AK-notebook.png

But I'd like to display lines that fill up the screen e.g. http://www.itismyworld.info/wp-content/uploads/2010/03/AK-notebook.png

任何建議都會(huì)很棒.相關(guān)的代碼似乎在這里:

Any suggestions would be great. The relevent bit of code seems to be here:

    protected void onDraw(Canvas canvas) {

        // Gets the number of lines of text in the View.
        int count = getLineCount();

        // Gets the global Rect and Paint objects
        Rect r = mRect;
        Paint paint = mPaint;

        /*
         * Draws one line in the rectangle for every line of text in the EditText
         */
        for (int i = 0; i < count; i++) {

            // Gets the baseline coordinates for the current line of text
            int baseline = getLineBounds(i, r);

            /*
             * Draws a line in the background from the left of the rectangle to the right,
             * at a vertical position one dip below the baseline, using the "paint" object
             * for details.
             */
            canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
        }

        // Finishes up by calling the parent method
        super.onDraw(canvas);
    }

推薦答案

這是代碼,基于 jkhouws1 的建議和 google 的 筆記編輯器

This is the code, based on jkhouws1's suggestion and google's note editor

public 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.FILL_AND_STROKE);
        mPaint.setColor(R.color.edit_note_line); //SET YOUR OWN COLOR HERE
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //int count = getLineCount();

        int height = getHeight();
        int line_height = getLineHeight();

        int count = height / line_height;

        if (getLineCount() > count)
            count = getLineCount();//for long text with scrolling

        Rect r = mRect;
        Paint paint = mPaint;
        int baseline = getLineBounds(0, r);//first line

        for (int i = 0; i < count; i++) {

            canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
            baseline += getLineHeight();//next line
        }

        super.onDraw(canvas);
    }
}

在 Eclipse IDE 中按 Ctrl+Shift+O 添加所有需要的導(dǎo)入

In Eclipse IDE press Ctrl+Shift+O to add all needed imports

這篇關(guān)于在edittext中繪制多行,例如記事本的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標(biāo)簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測(cè)向左或向右滑動(dòng)?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉(zhuǎn)對(duì)話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點(diǎn)擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設(shè)置為僅接受 Android 中的數(shù)值?)
主站蜘蛛池模板: 国产精品久久精品 | 国产日韩精品一区二区 | 五月婷婷丁香婷婷 | 欧美在线播放一区 | 香蕉久久a毛片 | 美女午夜影院 | 噜噜噜色网| 一区| 成人精品鲁一区一区二区 | 亚洲一区二区三区在线播放 | 亚洲欧美中文日韩在线v日本 | 在线午夜电影 | 成在线人视频免费视频 | 亚洲日韩中文字幕一区 | 国产一区二区三区在线 | 精品成人在线观看 | 国产精品国产精品国产专区不卡 | 国产一区中文 | 91免费观看国产 | 拍拍无遮挡人做人爱视频免费观看 | 91国语清晰打电话对白 | 国产精品成av人在线视午夜片 | 日本一二三区高清 | 免费看的黄网站 | 国产1区2区在线观看 | 国产69精品久久99不卡免费版 | 亚洲精品大片 | 91久久久久久 | 综合色久| 成人国内精品久久久久一区 | 中文字幕亚洲一区二区三区 | 91在线精品视频 | www久久久 | 国产精品一码二码三码在线 | 国产在线精品一区二区 | 一区二区三区四区视频 | 国产日韩欧美在线 | 欧美 日本 国产 | 国产成人免费视频 | 伊人伊成久久人综合网站 | 久久神马 |