canvas.DrawText让文字真正居中显示
来源:互联网 发布:福州seo服务 编辑:程序博客网 时间:2024/05/21 08:35
canvas.drawColor(getResources().getColor(R.color.colorPrimary)); super.onDraw(canvas); float x = this.getX(); float y = this.getY(); int w = this.getWidth(); int h = this.getHeight(); Log.e("x", String.valueOf(x)); Log.e("y", String.valueOf(y)); Log.e("x+w/2", String.valueOf(x + w / 2)); Log.e("y+h/2", String.valueOf(y + h / 2)); Paint paint = new Paint(); Rect rect = new Rect(); paint.setTextAlign(Paint.Align.LEFT);// paint.setColor(getResources().getColor(R.color.white)); paint.getTextBounds("click to scale", 0 , "click to scale".length(), rect); paint.setAntiAlias(true);
Paint.FontMetrics metricsInt = paint.getFontMetrics();// canvas.drawText("click to scale",(getMeasuredWidth() - rect.width()) / 2,(getMeasuredHeight() - metricsInt.descent - metricsInt.ascent) / 2,paint); /** * because param y is not the text show in center,but the baseline ,so we must set the baseline instead of text to display in center * */ canvas.drawText("click to scale",(getMeasuredWidth() - rect.width()) / 2,(getMeasuredHeight() - (metricsInt.descent + metricsInt.ascent)) / 2,paint);
参考:http://blog.csdn.net/lovexieyuan520/article/details/43153275
源码下载:git@github.com:edwinsnao/AnimationDemo.git
0 0
- canvas.DrawText让文字真正居中显示
- android canvas drawText()文字居中
- Android Canvas drawText()文字居中
- canvas drawText文字垂直居中
- android canvas drawText()文字居中
- canvas drawText 如何居中显示。
- Android 中Canvas.drawText实现文字居中
- canvas.drawText文字居中(备忘)
- Android 史上最简单的实现Canvas drawText文字垂直居中
- Canvas drawText 不显示
- ANDROID drawText实现文字居中
- DrawText上下左右居中输出文字
- DrawText 显示平面文字
- 安卓开发——实现canvas.drawText文字水平且垂直居中
- 如何让TextView中的文字居中显示
- 如何让TextView中的文字居中显示?
- mfc 静态文本框让文字居中显示
- Android Canvas drawText实现中文垂直居中
- 如何在Mac OS X上关闭Emacs的自动保存功能?
- 98-10(fibonacci)
- Spring SpringMVC Mybatis项目总结
- ArrayList和LinkedList
- 剑指Offer----扩展:有趣的数字(腾讯)
- canvas.DrawText让文字真正居中显示
- 栈的应用-括号的匹配
- ROS_PCl_加载PCD点云数据文件与接收点云并保存
- CSS 文本样式(上)(20160817-0017)
- Android自定义SeekBar的样式
- java解析xml
- UML类图画法
- 在网页中添加背景音乐
- iOS直播app原理