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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值