Android Text文字详解
1.绘制文字
1.1 普通绘写文字
- drawText(String text, float x, float y, Paint paint):直接进行文字绘制
- drawText(CharSequence text, int start, int end, float x, float y, Paint paint):
- drawText(char[] text, int index, int count, float x, float y, Paint paint):可对输入内容进行截取
- drawText(String text, int start, int end, float x, float y, Paint paint):可对输入内容进行截取
注意: charSequence不支持spannableString
1.2 单独指定每个文字的位置
- drawPosText(char[] text, int index, int count, float[] pos, Paint paint)
- drawPosText(String text, float[] pos, Paint paint)
注意:此方法不支持字形组合和分解,因此不应用于呈现复杂脚本。它也不处理补充字符(如表情符号)。
1.3 沿路径绘写文字
- drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint)
- drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, float vOffset, Paint paint)
- hOffset:沿路径给文本的起始位置添加偏移距离
- vOffset: 与路径中心的垂直偏移量
待续。。
2.字体样式
2.1 Paint相关样式
- setUnderlineText(true);//下划线
- setStrikeThruText(true);//删除线
- setTextSkewX((float) 0);//倾斜度(普通斜体字是-0.25,负数为右斜,正为左斜)
- setFakeBoldText(true);//粗体
- setTextScaleX(1);//水平拉伸(仅仅水平方向拉伸,高度不变)
2.2 Typeface字体样式
- defaultFromStyle(int style)
- create(String familyName, int style)
- create(Typeface family, int style)
- createFromAsset(AssetManager mgr, String path):从Assets中获取
- createFromFile(String path) :从路径中获取
- createFromFile(File path) :从外部路径获取
在main下新建 assets/fonts 目录,把第三方的字体文件*.ttf放进去,其中字体文件可以在C:\Windows\Fonts中获取后网上下载
参考资料
https://blog.csdn.net/harvic880925/article/details/38926877
http://www.android-doc.com/reference/android/graphics/Canvas.html
http://www.android-doc.com/reference/android/graphics/Typeface.html
作者:Brainbg(白雨)
GitHub:https://github.com/Brainbg
博客:https://www.brainbg.com/
简书:https://www.jianshu.com/u/94518ede7100
CSDN:https://blog.csdn.net/u014720022