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


Java TextPaint.getFontMetrics方法代码示例

本文整理汇总了Java中android.text.TextPaint.getFontMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java TextPaint.getFontMetrics方法的具体用法?Java TextPaint.getFontMetrics怎么用?Java TextPaint.getFontMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.text.TextPaint的用法示例。


在下文中一共展示了TextPaint.getFontMetrics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: TextRun

import android.text.TextPaint; //导入方法依赖的package包/类
TextRun(int offset, int length, boolean isRotated, boolean isSpanned) {

            this.offset = offset;
            this.length = length;
            this.isRotated = isRotated;

            TextPaint wp;
            if (isSpanned) {
                wp = mWorkPaint;
                wp.set(mPaint);
                MetricAffectingSpan[] spans = ((Spanned) mText).getSpans(offset, offset + length, MetricAffectingSpan.class);
                for(MetricAffectingSpan span : spans) {
                    span.updateDrawState(wp);
                }
            } else {
                wp = mPaint;
            }

            // just record the normal non-rotated values here
            // measure and draw will take rotation into account
            measuredWidth = wp.measureText(mText, offset, offset + length);
            measuredHeight = wp.getFontMetrics().bottom - wp.getFontMetrics().top;
        }
 
开发者ID:suragch,项目名称:mongol-library,代码行数:24,代码来源:MongolTextLine.java

示例2: TMReminderTagsView

import android.text.TextPaint; //导入方法依赖的package包/类
public TMReminderTagsView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    if (mDensity == -1) {
        initWith(context);
    }
    textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setColor(Color.rgb(255, 59, 68));
    textPaint.setTextSize(dp2px(10));

    bgPaint = new Paint();
    bgPaint.setColor(Color.rgb(250, 211, 213));

    tagsGap = dp2px(7);

    hPadding = dp2px(3);

    tagRect = new Rect();

    textFontMetrics = textPaint.getFontMetrics();
}
 
开发者ID:alibaba,项目名称:Virtualview-Android,代码行数:22,代码来源:TMReminderTagsView.java

示例3: RoundedIconGenerator

import android.text.TextPaint; //导入方法依赖的package包/类
/**
 * Constructs the generator and initializes the common members ignoring display density.
 *
 * @param iconWidthPx The width of the generated icon in pixels.
 * @param iconHeightPx The height of the generated icon in pixels.
 * @param cornerRadiusPx The radius of the corners in the icon in pixels.
 * @param backgroundColor Color at which the rounded rectangle should be drawn.
 * @param textSizePx Size at which the text should be drawn in pixels.
 */
public RoundedIconGenerator(int iconWidthPx, int iconHeightPx, int cornerRadiusPx,
        int backgroundColor, float textSizePx) {
    mIconWidthPx = iconWidthPx;
    mIconHeightPx = iconHeightPx;
    mCornerRadiusPx = cornerRadiusPx;

    mBackgroundRect = new RectF(0, 0, mIconWidthPx, mIconHeightPx);

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setColor(backgroundColor);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setFakeBoldText(true);
    mTextPaint.setTextSize(textSizePx);

    FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
    mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
    mTextYOffset = -textFontMetrics.top;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:30,代码来源:RoundedIconGenerator.java

示例4: SelectRegoinDecoration

import android.text.TextPaint; //导入方法依赖的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

示例5: init

import android.text.TextPaint; //导入方法依赖的package包/类
private void init() {
    borderPaint = new Paint();
    borderPaint.setColor(borderColor);
    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setStrokeWidth(borderWidth);
    rectPaint = new Paint();
    rectPaint.setColor(rectColor);
    rectPaint.setStyle(Paint.Style.FILL);
    linePaint = new Paint();
    linePaint.setAntiAlias(true);
    linePaint.setColor(lineColor);
    linePaint.setStyle(Paint.Style.STROKE);
    linePaint.setStrokeWidth(lineWidth);
    linePaint.setStrokeJoin(Paint.Join.ROUND);
    textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setColor(textColor);
    textPaint.setTextSize(textSize);
    fm = textPaint.getFontMetrics();
    path = new Path();
    pathDst = new Path();
    pm = new PathMeasure();
    selectedIndex = -1;
}
 
开发者ID:huzenan,项目名称:EasyChart,代码行数:25,代码来源:EasyGraphHistogram.java

示例6: getDesiredSize

import android.text.TextPaint; //导入方法依赖的package包/类
/**
 * Return how wide a layout must be in order to display the
 * specified text slice with one line per paragraph.
 */
public static Rect getDesiredSize(CharSequence source,
                                  int start, int end,
                                  TextPaint paint) {

    MongolTextLine tl = MongolTextLine.obtain();

    float longestWidth = 0;
    float heightSum = 0;

    int next;
    for (int i = start; i <= end; i = next) {
        next = TextUtils.indexOf(source, '\n', i, end);

        if (next < 0)
            next = end;

        tl.set(paint, source, i, next);
        RectF size = tl.measure();
        float width = size.width(); // horizontal line orientation
        heightSum += size.height(); // horizontal line orientation

        if (width > longestWidth)
            longestWidth = width;

        next++;
    }

    MongolTextLine.recycle(tl);

    if (heightSum == 0) {
        heightSum = paint.getFontMetrics().bottom - paint.getFontMetrics().top;
    }

    // returning the size as a vertical line orientation (swapping width and height)
    return new Rect(0, 0, (int) heightSum, (int) longestWidth);
}
 
开发者ID:suragch,项目名称:mongol-library,代码行数:41,代码来源:MongolLayout.java

示例7: TitleBitmapFactory

import android.text.TextPaint; //导入方法依赖的package包/类
/**
 * @param context   The current Android's context.
 * @param incognito Whether the title are for incognito mode.
 * @param nullFaviconResourceId A drawable resource id of a default favicon.
 */
public TitleBitmapFactory(Context context, boolean incognito, int nullFaviconResourceId) {
    mNullFaviconResourceId = nullFaviconResourceId;

    Resources res = context.getResources();
    int textColor = ApiCompatibilityUtils.getColor(res, incognito
            ? R.color.compositor_tab_title_bar_text_incognito
            : R.color.compositor_tab_title_bar_text);
    float textSize = res.getDimension(R.dimen.compositor_tab_title_text_size);

    boolean fakeBoldText = res.getBoolean(R.bool.compositor_tab_title_fake_bold_text);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(textColor);

    mTextPaint.setTextSize(textSize);
    mTextPaint.setFakeBoldText(fakeBoldText);
    mTextPaint.density = res.getDisplayMetrics().density;

    FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
    mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
    mTextYOffset = -textFontMetrics.top;

    mFaviconDimension = res.getDimensionPixelSize(R.dimen.compositor_tab_title_favicon_size);
    mViewHeight = (int) Math.max(mFaviconDimension, mTextHeight);

    int width = res.getDisplayMetrics().widthPixels;
    int height = res.getDisplayMetrics().heightPixels;
    mMaxWidth = (int) (TITLE_WIDTH_PERCENTAGE * Math.max(width, height));

    // Set the favicon dimension here.
    mFaviconDimension = Math.min(mMaxWidth, mFaviconDimension);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:38,代码来源:TitleBitmapFactory.java

示例8: getTextOffsetY

import android.text.TextPaint; //导入方法依赖的package包/类
private int getTextOffsetY(TextPaint paint, int gravity) {
    int height = (int) (paint.getFontMetrics().descent - paint.getFontMetrics().ascent);
    int offset = (int) (paint.getFontMetrics().descent + paint.getFontMetrics().ascent) / 2;
    if ((gravity & Gravity.CENTER_VERTICAL) != 0) {
        offset += height / 2;
    } else if ((gravity & Gravity.BOTTOM) != 0) {
        offset += height;
    }
    return offset;
}
 
开发者ID:auv1107,项目名称:CurveView,代码行数:11,代码来源:CurveView.java

示例9: setBadge

import android.text.TextPaint; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public void setBadge(String text) {

    TextPaint textPaint = mTvBadge.getPaint();
    float textWidth = textPaint.measureText(text);
    Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
    float textHeight = fontMetrics.bottom - fontMetrics.top;

    int width = (int) Math.max(textWidth, textHeight);

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mTvBadge.getLayoutParams();
    params.width = width;
    params.height = width;
    mTvBadge.setLayoutParams(params);
    mTvBadge.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);

    int radius = width / 2;

    RoundRectShape shape = new RoundRectShape(new float[] {radius, radius, radius, radius, radius, radius, radius, radius}, null, null);
    ShapeDrawable backgroundDrawable = new ShapeDrawable(shape);
    backgroundDrawable.getPaint().setColor(Color.parseColor("#ff0000"));
    backgroundDrawable.setAlpha(100);
    mTvBadge.setBackground(backgroundDrawable);

    mTvBadge.setText(text);

}
 
开发者ID:rawray,项目名称:RRFramework-Android,代码行数:28,代码来源:TextRecyclerCellViewHolder.java

示例10: getMaxTextRectHeight

import android.text.TextPaint; //导入方法依赖的package包/类
/**
 * get the height which limited line count
 *
 * @param typeface
 * @param maxLineCount
 * @return
 */
private int getMaxTextRectHeight(String typeface, int maxLineCount) {
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mDefaultMinTextSize, mContext.getResources().getDisplayMetrics()));
    if (typeface != null) {
        textPaint.setTypeface(Typeface.createFromAsset(mContext.getAssets(), typeface));
    }
    Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
    int textHeight = (int) Math.ceil(fontMetrics.bottom - fontMetrics.top);
    return textHeight * maxLineCount + (int) (textHeight * 0.9f) * (maxLineCount - 1);
}
 
开发者ID:MaYatKit,项目名称:Rotatable-Scalable-Font,代码行数:18,代码来源:WidgetTextFactory.java

示例11: drawMultilineText

import android.text.TextPaint; //导入方法依赖的package包/类
public static void drawMultilineText(Canvas c, StaticLayout textLayout,
                                     float x, float y,
                                     TextPaint paint,
                                     MPPointF anchor, float angleDegrees) {

    float drawOffsetX = 0.f;
    float drawOffsetY = 0.f;
    float drawWidth;
    float drawHeight;

    final float lineHeight = paint.getFontMetrics(mFontMetricsBuffer);

    drawWidth = textLayout.getWidth();
    drawHeight = textLayout.getLineCount() * lineHeight;

    // Android sometimes has pre-padding
    drawOffsetX -= mDrawTextRectBuffer.left;

    // Android does not snap the bounds to line boundaries,
    //  and draws from bottom to top.
    // And we want to normalize it.
    drawOffsetY += drawHeight;

    // To have a consistent point of reference, we always draw left-aligned
    Paint.Align originalTextAlign = paint.getTextAlign();
    paint.setTextAlign(Paint.Align.LEFT);

    if (angleDegrees != 0.f) {

        // Move the text drawing rect in a way that it always rotates around its center
        drawOffsetX -= drawWidth * 0.5f;
        drawOffsetY -= drawHeight * 0.5f;

        float translateX = x;
        float translateY = y;

        // Move the "outer" rect relative to the anchor, assuming its centered
        if (anchor.x != 0.5f || anchor.y != 0.5f) {
            final FSize rotatedSize = getSizeOfRotatedRectangleByDegrees(
                    drawWidth,
                    drawHeight,
                    angleDegrees);

            translateX -= rotatedSize.width * (anchor.x - 0.5f);
            translateY -= rotatedSize.height * (anchor.y - 0.5f);
            FSize.recycleInstance(rotatedSize);
        }

        c.save();
        c.translate(translateX, translateY);
        c.rotate(angleDegrees);

        c.translate(drawOffsetX, drawOffsetY);
        textLayout.draw(c);

        c.restore();
    } else {
        if (anchor.x != 0.f || anchor.y != 0.f) {

            drawOffsetX -= drawWidth * anchor.x;
            drawOffsetY -= drawHeight * anchor.y;
        }

        drawOffsetX += x;
        drawOffsetY += y;

        c.save();

        c.translate(drawOffsetX, drawOffsetY);
        textLayout.draw(c);

        c.restore();
    }

    paint.setTextAlign(originalTextAlign);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:77,代码来源:Utils.java

示例12: getFontHeight

import android.text.TextPaint; //导入方法依赖的package包/类
private static int getFontHeight(TextPaint paint){
    Paint.FontMetrics fm = paint.getFontMetrics();
    return (int) Math.ceil(fm.descent - fm.top) + 2;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:DanmakuItem.java

示例13: onDraw

import android.text.TextPaint; //导入方法依赖的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

示例14: getFontHeight

import android.text.TextPaint; //导入方法依赖的package包/类
/**
 *得到文字的高度
 */
private float getFontHeight(TextPaint paint) {
    Paint.FontMetrics fm = paint.getFontMetrics();// 得到系统默认字体属性
    return fm.bottom - fm.top;
}
 
开发者ID:auv1107,项目名称:TextEmoji,代码行数:8,代码来源:TextEmoji.java

示例15: init

import android.text.TextPaint; //导入方法依赖的package包/类
private void init(Context context, AttributeSet attrs) {

        if (attrs != null) {
            TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.LabelView, 0, 0);
            try {
                textValue = a.getString(R.styleable.LabelView_textValue);
                labelValue = a.getString(R.styleable.LabelView_labelValue);
                lineColour = a.getColor(R.styleable.LabelView_lineColour, ContextCompat.getColor(context, DEFAULT_LINE_COLOR));
                textColour = a.getColor(R.styleable.LabelView_textColour, ContextCompat.getColor(context, DEFAULT_TEXT_COLOR));
                labelColour = a.getColor(R.styleable.LabelView_labelColour, ContextCompat.getColor(context, DEFAULT_TEXT_COLOR));
                lineThickness = a.getFloat(R.styleable.LabelView_lineThickness, 4f);
                labelSize = a.getDimensionPixelSize(R.styleable.LabelView_labelSize, (int) DEFAULT_TEXT_SIZE);
                textSize = a.getDimensionPixelSize(R.styleable.LabelView_textSize, (int) DEFAULT_TEXT_SIZE);
            } finally {
                a.recycle();
            }
        } else {
            textSize = labelSize = (int) DEFAULT_TEXT_SIZE;
            lineColour = ContextCompat.getColor(context, DEFAULT_LINE_COLOR);
            textColour = ContextCompat.getColor(context, DEFAULT_TEXT_COLOR);
            labelColour = textColour;
            lineThickness = DEFAULT_LINE_THICKNESS;
        }

        if (textValue == null) textValue = "";
        if (labelValue == null) labelValue = "";

        linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        linePaint.setColor(lineColour);
        linePaint.setStyle(Paint.Style.STROKE);
        linePaint.setStrokeWidth(lineThickness);
        linePaint.setStrokeCap(Paint.Cap.SQUARE);
        textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);

        textPaint.setColor(textColour);
        textPaint.setTextSize(textSize);
        textPaint.setStyle(Paint.Style.FILL);

        labelPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        labelPaint.setColor(labelColour);
        labelPaint.setTextSize(labelSize);
        textMetrics = textPaint.getFontMetrics();
        labelMetrics = labelPaint.getFontMetrics();

        textBounds = new Rect();
        labelBounds = new Rect();
    }
 
开发者ID:ppetarr,项目名称:Android-LabelView,代码行数:48,代码来源:LabelView.java


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