本文整理汇总了Java中android.graphics.Paint.FontMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java Paint.FontMetrics方法的具体用法?Java Paint.FontMetrics怎么用?Java Paint.FontMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Paint
的用法示例。
在下文中一共展示了Paint.FontMetrics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FloatingBarItemDecoration
import android.graphics.Paint; //导入方法依赖的package包/类
public FloatingBarItemDecoration(Context context, Map<Integer, String> list) {
this.mContext = context;
Resources resources = mContext.getResources();
this.mList = list;
this.mTitleHeight = resources.getDimensionPixelSize(R.dimen.item_decoration_title_height);
mBackgroundPaint = new Paint();
mBackgroundPaint.setColor(ContextCompat.getColor(mContext, R.color.item_decoration_title_background));
mTextPaint = new Paint();
mTextPaint.setColor(ContextCompat.getColor(mContext, R.color.item_decoration_title_fontcolor));
mTextPaint.setTextSize(mContext.getResources().getDimensionPixelSize(R.dimen.item_decoration_title_fontsize));
Paint.FontMetrics fm = mTextPaint.getFontMetrics();
mTextHeight = (int) (fm.bottom - fm.top);
mTextBaselineOffset = (int) fm.bottom;
mTextStartMargin = resources.getDimensionPixelOffset(R.dimen.item_decoration_title_start_margin);
}
示例2: MeiZuCalendarCardView
import android.graphics.Paint; //导入方法依赖的package包/类
public MeiZuCalendarCardView(Context context) {
super(context);
mTextPaint.setTextSize(dipToPx(context, 8));
mTextPaint.setColor(0xff111111);
mTextPaint.setAntiAlias(true);
mTextPaint.setFakeBoldText(true);
mSchemeBasicPaint.setAntiAlias(true);
mSchemeBasicPaint.setStyle(Paint.Style.FILL);
mSchemeBasicPaint.setTextAlign(Paint.Align.CENTER);
mSchemeBasicPaint.setColor(0xffed5353);
mSchemeBasicPaint.setFakeBoldText(true);
mRadio = dipToPx(getContext(), 7);
mPadding = dipToPx(getContext(), 4);
Paint.FontMetrics metrics = mSchemeBasicPaint.getFontMetrics();
mSchemeBaseLine = mRadio - metrics.descent + (metrics.bottom - metrics.top) / 2 + dipToPx(getContext(), 1);
}
示例3: SelectRegoinDecoration
import android.graphics.Paint; //导入方法依赖的package包/类
public SelectRegoinDecoration(Context context, DecorationCallback decorationCallback) {
Resources res = context.getResources();
this.callback = decorationCallback;
paint = new Paint();
paint.setColor(res.getColor(R.color.regoin_line));
textPaint = new TextPaint();
textPaint.setTypeface(Typeface.DEFAULT);
textPaint.setAntiAlias(true);
textPaint.setTextSize(30);
textPaint.setColor(Color.BLACK);
textPaint.getFontMetrics(fontMetrics);
textPaint.setTextAlign(Paint.Align.LEFT);
fontMetrics = new Paint.FontMetrics();
//高度
topGap = res.getDimensionPixelSize(R.dimen.sectioned_top);
}
示例4: getSize
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(final Paint paint, final CharSequence text, final int start,
final int end, final Paint.FontMetricsInt fontMetrics) {
if (fontMetrics != null) {
final Paint.FontMetrics paintFontMetrics = paint.getFontMetrics();
final float fontHeight = paintFontMetrics.descent - paintFontMetrics.ascent;
final float centerY = paintFontMetrics.ascent + fontHeight / 2;
fontMetrics.ascent = (int) (centerY - mEmoticonSize / 2);
fontMetrics.top = fontMetrics.ascent;
fontMetrics.bottom = (int) (centerY + mEmoticonSize / 2);
fontMetrics.descent = fontMetrics.bottom;
}
return (int) mEmoticonSize;
}
示例5: calculateTextHeight
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* Calculates the height of a given string at a specific text size.
*/
public static int calculateTextHeight(float textSizePx) {
Paint p = new Paint();
p.setTextSize(textSizePx);
Paint.FontMetrics fm = p.getFontMetrics();
return (int) Math.ceil(fm.bottom - fm.top);
}
示例6: initPadding
import android.graphics.Paint; //导入方法依赖的package包/类
private void initPadding() {
extraPaddingTop = floatingLabelEnabled ? floatingLabelTextSize + floatingLabelPadding : floatingLabelPadding;
textPaint.setTextSize(bottomTextSize);
Paint.FontMetrics textMetrics = textPaint.getFontMetrics();
extraPaddingBottom = (int) ((textMetrics.descent - textMetrics.ascent) * currentBottomLines) + (hideUnderline ? bottomSpacing : bottomSpacing * 2);
extraPaddingLeft = iconLeftBitmaps == null ? 0 : (iconOuterWidth + iconPadding);
extraPaddingRight = iconRightBitmaps == null ? 0 : (iconOuterWidth + iconPadding);
correctPaddings();
}
示例7: getFontHeight
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* get text height by font size
*
* @param fontSize
* @return
*/
private static int getFontHeight(float fontSize) {
Paint paint = new Paint();
paint.setTextSize(fontSize);
Paint.FontMetrics fm = paint.getFontMetrics();
return (int) Math.ceil(fm.descent - fm.top) + 2;
}
示例8: onDraw
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
int listIndex = 1;
CssEnum listStyleType = getComputedStyle().getEnum(CssProperty.LIST_STYLE_TYPE);
float scale = getOwnerDocument().getSettings().getScale();
Paint.FontMetrics bulletMetrics = null;
for (int i = 0; i < getChildCount(); i++) {
View component = getChildAt(i);
Element element = (Element) component;
CssStyleDeclaration childStyle = element.getComputedStyle();
if (childStyle.getEnum(CssProperty.DISPLAY) == CssEnum.LIST_ITEM
&& listStyleType != CssEnum.NONE) {
if (bulletMetrics == null) {
bulletMetrics = new Paint.FontMetrics();
}
String bullet = Strings.getBullet(listStyleType, listIndex++);
AndroidCss.setTextPaint(childStyle, scale, paint);
paint.getFontMetrics(bulletMetrics);
float top = childStyle.getPx(CssProperty.BORDER_TOP_WIDTH, 0)
+ childStyle.getPx(CssProperty.PADDING_TOP, 0);
float left = childStyle.getPx(CssProperty.BORDER_LEFT_WIDTH, 0)
+ childStyle.getPx(CssProperty.PADDING_LEFT, 0);
canvas.drawText(
bullet,
component.getX() + left * scale - paint.measureText(bullet),
component.getY() + top * scale - bulletMetrics.top,
paint);
}
}
}
示例9: measureView
import android.graphics.Paint; //导入方法依赖的package包/类
private void measureView()
{
float textWidth = textPaint.measureText(text.toString());
Paint.FontMetrics metrics = textPaint.getFontMetrics();
float textHeight = metrics.bottom - metrics.top;
circleRadius =
(int)Math.round((Math.sqrt(textWidth * textWidth + textHeight * textHeight) + circleStrokeWidth) / 2.0f);
width = getPaddingLeft() + circleRadius * 2 + circleStrokeWidth + getPaddingRight();
height = getPaddingTop() + circleRadius * 2 + circleStrokeWidth + getPaddingBottom();
}
示例10: drawText
import android.graphics.Paint; //导入方法依赖的package包/类
private void drawText(Canvas canvas, Rect rect) {
int margin = 40;
mPaint.setColor(mTextColor);
mPaint.setTextSize(getResources().getDimension(R.dimen.text_size_13sp));
String text = getResources().getString(R.string.auto_scan_notification);
Paint.FontMetrics fontMetrics = mPaint.getFontMetrics();
float fontTotalHeight = fontMetrics.bottom - fontMetrics.top;
float offY = fontTotalHeight / 2 - fontMetrics.bottom;
float newY = rect.bottom + margin + offY;
float left = (ScreenUtils.getScreenWidth() - mPaint.getTextSize() * text.length()) / 2;
canvas.drawText(text, left, newY, mPaint);
}
示例11: getTextYCenter
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* 在使用drawText方法时文字不能根据y坐标居中,所以重新计算y坐标
* @param paint
* @param y
* @return
*/
private float getTextYCenter(Paint paint, int y) {
Paint.FontMetrics fontMetrics = paint.getFontMetrics();
float fontTotalHeight = fontMetrics.bottom - fontMetrics.top;
float offY = fontTotalHeight / 2 - fontMetrics.bottom;
return y + offY;
}
示例12: onDraw
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
String text = "This is a custom view with setTypeface support";
Paint.FontMetrics fm = paint.getFontMetrics();
paint.getTextBounds(text, 0, text.length(), textBounds);
width = textBounds.left + textBounds.right + getPaddingLeft() + getPaddingRight();
height = (int) (Math.abs(fm.top) + fm.bottom);
canvas.drawText(text, 0, -fm.top + getPaddingTop(), paint);
}
示例13: getFontLeading
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* 返回指定笔离文字顶部的基准距离
*/
private float getFontLeading(Paint paint) {
Paint.FontMetrics fm = paint.getFontMetrics();
return fm.leading - fm.ascent;
}
示例14: onDraw
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
TextPaint paint = getPaint();
paint.setColor(getCurrentTextColor());
paint.drawableState = getDrawableState();
width = getMeasuredWidth();
Paint.FontMetrics fm = paint.getFontMetrics();
float firstHeight = getTextSize() - (fm.bottom - fm.descent + fm.ascent - fm.top);
int gravity = getGravity();
if ((gravity & 0x1000) == 0) { // 是否垂直居中
firstHeight = firstHeight + (textHeight - firstHeight) / 2;
}
int paddingTop = getPaddingTop();
int paddingLeft = getPaddingLeft();
int paddingRight = getPaddingRight();
width = width - paddingLeft - paddingRight;
for (int i = 0; i < lines.size(); i++) {
float drawY = i * textHeight + firstHeight;
String line = lines.get(i);
// 绘画起始x坐标
float drawSpacingX = paddingLeft;
float gap = (width - paint.measureText(line));
float interval = gap / (line.length() - 1);
// 绘制最后一行
if (tailLines.contains(i)) {
interval = 0;
if (align == Align.ALIGN_CENTER) {
drawSpacingX += gap / 2;
} else if (align == Align.ALIGN_RIGHT) {
drawSpacingX += gap;
}
}
for (int j = 0; j < line.length(); j++) {
float drawX = paint.measureText(line.substring(0, j)) + interval * j;
canvas.drawText(line.substring(j, j + 1), drawX + drawSpacingX, drawY +
paddingTop + textLineSpaceExtra * i, paint);
}
}
}
示例15: onDraw
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
if (getVisibility() != VISIBLE) {
return;
}
if (drawBackground || progress != 0) {
eraser2.setStrokeWidth(AndroidUtilities.dp(size + 6));
drawBitmap.eraseColor(0);
float rad = getMeasuredWidth() / 2;
float roundProgress = progress >= 0.5f ? 1.0f : progress / 0.5f;
float checkProgress = progress < 0.5f ? 0.0f : (progress - 0.5f) / 0.5f;
float roundProgressCheckState = isCheckAnimation ? progress : (1.0f - progress);
if (roundProgressCheckState < progressBounceDiff) {
rad -= AndroidUtilities.dp(2) * roundProgressCheckState / progressBounceDiff;
} else if (roundProgressCheckState < progressBounceDiff * 2) {
rad -= AndroidUtilities.dp(2) - AndroidUtilities.dp(2)
* (roundProgressCheckState - progressBounceDiff) / progressBounceDiff;
}
if (drawBackground) {
paint.setColor(0x44000000);
canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2,
rad - AndroidUtilities.dp(1), paint);
canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2,
rad - AndroidUtilities.dp(1), backgroundPaint);
}
paint.setColor(color);
bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, rad, paint);
bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2,
rad * (1 - roundProgress), eraser);
canvas.drawBitmap(drawBitmap, 0, 0, null);
// 选中时显示√
// checkBitmap.eraseColor(0);
// int w = checkDrawable.getIntrinsicWidth();
// int h = checkDrawable.getIntrinsicHeight();
// int x = (getMeasuredWidth() - w) / 2;
// int y = (getMeasuredHeight() - h) / 2;
//
// checkDrawable.setBounds(x, y + checkOffset, x + w, y + h + checkOffset);
// checkDrawable.draw(checkCanvas);
// checkCanvas.drawCircle(getMeasuredWidth() / 2 - AndroidUtilities.dp(2.5f),
// getMeasuredHeight() / 2 + AndroidUtilities.dp(4), ((getMeasuredWidth() +
// AndroidUtilities.dp(6)) / 2) * (1 - checkProgress), eraser2);
//
// canvas.drawBitmap(checkBitmap, 0, 0, null);
// 选中时显示数字
if (isChecked && number != -1) {
int w = getMeasuredWidth() / 2;
int h = getMeasuredHeight();
textPaint.setTextSize(w);
Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
// 计算文字高度
float fontHeight = fontMetrics.bottom - fontMetrics.top;
// 计算文字baseline
float baseY = h - (h - fontHeight) / 2 - fontMetrics.bottom;
canvas.drawText(String.valueOf(number), w, baseY, textPaint);
}
}
}