2011.09.26(3)——— android sample之Notepad(带下划线的TestView)
参考:
http://www.cnblogs.com/phinecos/archive/2009/08/27/1555221.html
notepad里面用于记事的TextView
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);
}
}
主要工作就是重载onDraw方法,利用从TextView继承下来的getLineCount函数获取文本所占的行数,以及getLineBounds来获取特定行的基准高度值,而且这个函数第二个参数会返回此行的“外包装”值。再利用这些值绘制这一行的线条。
xml
<view xmlns:android="http://schemas.android.com/apk/res/android"
class="com.example.android.notepad.NoteEditor$LinedEditText"
android:id="@+id/note"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:padding="5dip"
android:scrollbars="vertical"
android:fadingEdge="vertical"
android:gravity="top"
android:textSize="22sp"
android:capitalize="sentences"
/>
分享到:
相关推荐
NULL 博文链接:https://trylovecatch.iteye.com/blog/1178999
安卓Android源码——NotePad便签.zip
notepad++文本编辑器7.9.3
notepad_share_encrypt.hdoc..bin
Notepad++7.9.3.exe安装包,解压后可见安装包,全名:npp.7.9.3.Installer.exe
android入门Notepad+源代码.rar,很好的入门源码,里面有详细的中文解释,或许能帮倒你
Notepad++ 插件,AndroidLogger.V1.2.7. 可以让安卓日志自动显示颜色,告别白色背景 黑色字体!确保 打开的文件是.log后缀的。
notepad.notepad.notepad.notepad.notepad.notepad.notepad.
AndroidLogger——MGYH.zip
Notepad3是一个快速、轻量级的基于scintilla的文本编辑器,具有语法高亮显示功能。 它占用的内存很少,但功能强大,足以处理大多数编程作业。
notepad++绿色版,免费版,直接解压就行,Notepad++.7.6.1
Windows-Notepad++(7.9.3)
npp.8.3.3.Installer.x64.exe Notepad++
notepad++.7.8.2.Installer.x32.exe,官网下载的安装包,轻量级又方便快速的记事本,这是32位的
Notepad
NotePad.rar
用java实现仿windows上的记事本 学习awt的有关知识............................................................................................................................................................
《逆向工程核心原理》一书中使用的程序notepad_upx.exe ,包括NOTEPAD.EXE ,UPX程序
android NotePad便签源码.rar
The list below provides a summary of the sample applications that are available with the Android SDK. Using the links on this page, you can view the source files of the sample applications in your ...