本文整理匯總了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();
}
}