`
1846396994
  • 浏览: 72399 次
社区版块
存档分类
最新评论

Android自定义view-文本自动换行

 
阅读更多

文本自动换行原理:文本超出控件宽度后,自动换到下一行绘制。 实现代码:protected void onDraw(Canvas canvas) {         FontMetrics fm = mPaint.getFontMetrics(); float baseline = fm.descent - fm.ascent;  float x = 0; float y =  baseline;  //由于系统基于字体的底部来绘制文本,所有需要加上字体的高度。 String txt = getResources().getString(com.orgcent.demo.R.string.hello); //文本自动换行 String[] texts = autoSplit(txt, mPaint, getWidth() - 5); System.out.printf("line indexs: %s\n", Arrays.toString(texts)); for(String text : texts) { 



原文地址:Android自定义view-文本自动换行 | http://orgcent.com/android-custom-view-text-wrap/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics