本文整理汇总了Java中android.text.TextPaint.getFontMetricsInt方法的典型用法代码示例。如果您正苦于以下问题:Java TextPaint.getFontMetricsInt方法的具体用法?Java TextPaint.getFontMetricsInt怎么用?Java TextPaint.getFontMetricsInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.TextPaint
的用法示例。
在下文中一共展示了TextPaint.getFontMetricsInt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDraw
import android.text.TextPaint; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
if (!mIsVerticalMode) {
super.onDraw(canvas);
} else {
if (mLineCount == 0) {
return;
}
final TextPaint paint = getPaint();
paint.setColor(getCurrentTextColor());
paint.drawableState = getDrawableState();
final Paint.FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
final char[] chars = getText().toString().toCharArray();
canvas.save();
int curLine = 0;
float curLineX = getWidth() - getPaddingRight() - mLineWidths[curLine];
float curX = curLineX;
float curY = getPaddingTop();
for (int i = 0; i < chars.length; i++) {
final char c = chars[i];
// boolean needRotate = !Caches.isCJK(c);
boolean needRotate = !isCJKCharacter(c);
final int saveCount = canvas.save();
if (needRotate) {
canvas.rotate(90, curX, curY);
}
// draw
float textX = curX;
float textBaseline = needRotate ?
curY - (mLineWidths[curLine] - (fontMetricsInt.bottom - fontMetricsInt.top)) / 2 - fontMetricsInt.descent :
curY - fontMetricsInt.ascent;
canvas.drawText(chars, i, 1, textX, textBaseline, paint);
canvas.restoreToCount(saveCount);
// if break line
boolean hasNextChar = i + 1 < chars.length;
if (hasNextChar) {
// boolean breakLine = needBreakLine(i, mLineCharsCount, curLine);
boolean nextCharBreakLine = i + 1 > mLineBreakIndex[curLine];
if (nextCharBreakLine && curLine + 1 < mLineWidths.length) {
// new line
curLine++;
curLineX -= (mLineWidths[curLine] * getLineSpacingMultiplier() + getLineSpacingExtra());
curX = curLineX;
curY = getPaddingTop();
} else {
// move to next char
if (needRotate) {
curY += paint.measureText(chars, i, 1);
} else {
curY += fontMetricsInt.descent - fontMetricsInt.ascent;
}
}
}
}
canvas.restore();
}
}
示例2: onDraw
import android.text.TextPaint; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onDraw(Canvas canvas) {
if (!mIsVerticalMode) {
super.onDraw(canvas);
} else {
if (mLineCount == 0) {
return;
}
final TextPaint paint = getPaint();
paint.setColor(getCurrentTextColor());
paint.drawableState = getDrawableState();
final Paint.FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
final char[] chars = getText().toString().toCharArray();
canvas.save();
int curLine = 0;
float curLineX = getWidth() - getPaddingRight() - mLineWidths[curLine];
float curX = curLineX;
float curY = getPaddingTop();
for (int i = 0; i < chars.length; i++) {
final char c = chars[i];
// boolean needRotate = !Caches.isCJK(c);
boolean needRotate = !isCJKCharacter(c);
final int saveCount = canvas.save();
if (needRotate) {
canvas.rotate(90, curX, curY);
}
// draw
float textX = curX;
float textBaseline = needRotate ?
curY - (mLineWidths[curLine] - (fontMetricsInt.bottom - fontMetricsInt.top)) / 2 - fontMetricsInt.descent :
curY - fontMetricsInt.ascent;
canvas.drawText(chars, i, 1, textX, textBaseline, paint);
canvas.restoreToCount(saveCount);
// if break line
boolean hasNextChar = i + 1 < chars.length;
if (hasNextChar) {
// boolean breakLine = needBreakLine(i, mLineCharsCount, curLine);
boolean nextCharBreakLine = i + 1 > mLineBreakIndex[curLine];
if (nextCharBreakLine && curLine + 1 < mLineWidths.length) {
// new line
curLine++;
curLineX -= (mLineWidths[curLine] * getLineSpacingMultiplier() + getLineSpacingExtra());
curX = curLineX;
curY = getPaddingTop();
} else {
// move to next char
if (needRotate) {
curY += paint.measureText(chars, i, 1);
} else {
curY += fontMetricsInt.descent - fontMetricsInt.ascent;
}
}
}
}
canvas.restore();
}
}