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

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

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

問題描述

我正在查看 android SDK 中的記事本示例,請參見此處: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

問題是它只繪制光標所在的當前行,例如 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

任何建議都會很棒.相關的代碼似乎在這里:

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 添加所有需要的導入

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

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

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

相關文檔推薦

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 操作標簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設置為僅接受 Android 中的數值?)
主站蜘蛛池模板: av一区二区在线观看 | 在线观看亚洲专区 | 色综合九九| 欧美日韩中文字幕 | 1000部精品久久久久久久久 | 超碰地址 | 亚洲视频免费观看 | av资源网站| 精国产品一区二区三区 | 免费在线视频一区二区 | 欧美日韩亚洲视频 | 国产69精品久久99不卡免费版 | 久久精品97| 毛片入口| 欧美日韩国产在线 | 亚洲福利av | 美女天天操 | 国产毛片久久久 | 人成在线 | 精品国产1区2区3区 一区二区手机在线 | 欧美精品一区二区在线观看 | 国产欧美视频一区 | 欧美一区| 国产精品久久久久婷婷二区次 | 久久香蕉精品视频 | 毛片免费在线观看 | 国产日韩一区二区三区 | 国产精品性做久久久久久 | 99视频入口 | 狠狠干天天干 | 国产成人艳妇aa视频在线 | 91在线精品视频 | 日韩中文字幕一区二区 | 看片国产 | 免费观看一级黄色录像 | 天堂一区二区三区 | 中文字幕一区二区在线观看 | 欧美精品一区二区三区在线播放 | www.成人.com| 久久夜色精品国产 | 99久久免费精品视频 |