绘制系列(五)-DrawText()详解

绘制系列(五)-DrawText()详解

文字基础知识

1、setTextAlign()

设置文字对齐方式(起始点相对于文字)

canvas.drawText(“文字”,起始点,paint)

比如: paint.setTextAlign(Paint.Align.RIGHT)//表示起始点在文字的右侧开始绘制;

###2、设置字体样式 ###

  1. 设置粗体 setBoldText(boolean fakeBoldText)
  2. 设置下划线 setUnderLineText(boolean underLineText)
  3. 设置是否显示中间删除线 setStrikeThruText()
  4. 设置字体倾斜度 setTextSkewX(float skewX),取负值向右倾斜,取正值向左倾斜
  5. 水平拉伸 setTextScaleX(floate scaleX)取值为1,表示不拉伸
  6. 设置字体seTypeface(Typeface typeface);Typeface是字体样式的类,可以指定系统中的字体,也可以在自定义样式文件中获取

字体样式

  • Android中自带的字体样式,Typeface类中保存着三种自带字体样式,Typeface。SAN_SERIF、Typeface.MONOSPACE、Typeface.SERIF,这三种的字体对中文支持不很有友好,当遇到不支持的文字时,会使用系统默认的样式来写;

-Typeface create(String familyName,int style)
通过指定字体名来加载系统中自带的字体样式,如果字体样式不存在,则会用紫铜样式代替并返回;

一般情况下,我们会选择加载自定义的字体文件来绘制文字,而不是指定系统自带的字体样式;
要自定义字体样式:

  1. 从外部字体文件中加载所需字形

     Typeface createFromAsset(AssetManager mgr,String apth)
    
     createFromFile(String path)
    
     createFromFile(File path)
    

绘制文字

  1. public void drawText(String text, float x, float y,Paint paint)
  2. public void drawText(String text, int start, int end, float x, float y,Paint paint)
  3. public void drawText(CharSequence text, int start, int end, float x, float y,Paint paint)
  4. public void drawText(char[] text, int index, int count, float x, float y,Paint paint)
  5. public void drawTextOnPath(char[] text, int
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值