Android(安卓)字体相关内容
/**获得字体高度*/
Paint textPaint = new Paint( Paint.ANTI_ALIAS_FLAG);
Rect rect = new Rect();
textPaint.getTextBounds("辉", 0, 1, rect);
int fontHeight=rect.height()+2;
/**获得字体高度*/
=====================
paint.setAntiAlias(true);//去锯齿
===========字体居中============
/*Paint.Align 是文本对齐方式的一个枚举类
* CENTER表示文本居中
* LEFT 表示做对齐
* RIGHT 表示右对齐
*/
p.setTextAlign(Paint.Align.CENTER);
==========新方法==============
2011年2月17日
获得宽度
Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setColor(Color.WHITE);
// Define the string.
String displayText = “Hello World!”;
// Measure the width of the text string.
float textWidth = mTextPaint.measureText(displayText);
获得高度
public int getFontHeight(float fontSize)
{
Paint paint = new Paint();
paint.setTextSize(fontSize);
FontMetrics fm = paint.getFontMetrics();
return (int) Math.ceil(fm.descent - fm.top) + 2;
}
ps:原理
Canvas 作为绘制文本时,使用FontMetrics对象,计算位置的坐标。
它的思路和java.awt.FontMetrics的基本相同。
FontMetrics对象
它以四个基本坐标为基准,分别为:
・FontMetrics.top
・FontMetrics.ascent
・FontMetrics.descent
・FontMetrics.bottom
该图片将如下
=====================
2011年2月18日
字体风格Typeface种类
int Style类型
BOLD BOLD_ITALIC ITALIC NORMAL | 粗体 粗斜体 斜体 普通字体 |
Typeface类型
DEFAULT DEFAULT_BOLD MONOSPACE SANS_SERIF SERIF | 默认字体 默认粗体 单间隔字体 无衬线字体 衬线字体 |
Typeface.create(Typeface family,int style)
创建一个混合型新的字体:有4*5中搭配
Typeface.setTypeface (Typeface tf, int style)
设置一个混合型字体:有4*5中搭配
Typeface.setTypeface(Typeface tf)
设置一个只有Typeface风格的字体:有五种形式
更多相关文章
- android 模拟器获得root 权限
- Android(安卓)获得可用摄像头id
- Android文件操作
- Android(安卓)获取通讯录联系人
- LinearLayout中设置 水平且垂直 居中
- Android(安卓)GPS 获得 经纬度 并得到该 坐标 精确地址
- Android中向SD卡读写数据,读SD卡和手机内存
- 操作Android(安卓)手机通讯录数据库
- Android获得系统时间(24小时制)