当前位置: 首页>>代码示例>>Java>>正文


Java Paint.FontMetrics方法代码示例

本文整理汇总了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);
}
 
开发者ID:hgDendi,项目名称:ContactsList,代码行数:19,代码来源:FloatingBarItemDecoration.java

示例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);

}
 
开发者ID:yhyonghao,项目名称:CalendarView_master,代码行数:20,代码来源:MeiZuCalendarCardView.java

示例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);

}
 
开发者ID:funnyzhaov,项目名称:Tribe,代码行数:19,代码来源:SelectRegoinDecoration.java

示例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;
}
 
开发者ID:kevalpatel2106,项目名称:EmoticonGIFKeyboard,代码行数:17,代码来源:EmoticonSpan.java

示例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);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:10,代码来源:Utilities.java

示例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();
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:10,代码来源:MaterialEditText.java

示例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;
}
 
开发者ID:wheat7,项目名称:Cashew,代码行数:13,代码来源:BottomNavigationViewEx.java

示例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);
        }
    }
}
 
开发者ID:stefanhaustein,项目名称:nativehtml,代码行数:36,代码来源:AndroidContainerElement.java

示例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();
}
 
开发者ID:Dreamxiaoxuan,项目名称:AndroidTvDemo,代码行数:11,代码来源:CountDownProgress.java

示例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);
}
 
开发者ID:simplezhli,项目名称:Tesseract-OCR-Scanner,代码行数:13,代码来源:ScannerFinderView.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:SimpleMonthView.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:CustomViewWithTypefaceSupport.java

示例13: getFontLeading

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * 返回指定笔离文字顶部的基准距离
 */
private float getFontLeading(Paint paint) {
    Paint.FontMetrics fm = paint.getFontMetrics();
    return fm.leading - fm.ascent;
}
 
开发者ID:GitLqr,项目名称:MaterialDesignDemo,代码行数:8,代码来源:MyDecorationThree.java

示例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);
        }
    }
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:47,代码来源:AlignTextView.java

示例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);
        }
    }
}
 
开发者ID:chengzichen,项目名称:KrGallery,代码行数:67,代码来源:CheckBox.java


注:本文中的android.graphics.Paint.FontMetrics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。