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


Java Paint.getFontMetricsInt方法代码示例

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


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

示例1: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void draw(
    Canvas canvas,
    CharSequence text,
    int start,
    int end,
    float x,
    int top,
    int y,
    int bottom,
    Paint paint) {
  paint.getFontMetricsInt(mFontMetricsInt);
  int iconTop = y + getOffsetAboveBaseline(mFontMetricsInt);
  canvas.translate(x, iconTop);
  mDrawable.draw(canvas);
  canvas.translate(-x, -iconTop);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:BetterImageSpan.java

示例2: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void draw(@NonNull Canvas canvas, CharSequence text,
                 int start, int end, float x,
                 int top, int y, int bottom, @NonNull Paint paint) {
    Drawable d = getCachedDrawable();
    Rect rect = d.getBounds();
    canvas.save();
    final float fontHeight = paint.getFontMetrics().descent - paint.getFontMetrics().ascent;
    int transY = bottom - rect.bottom;
    if (rect.height() < fontHeight) { // this is the fucking code which I waste 3 days
        if (mVerticalAlignment == ALIGN_BASELINE) {
            transY -= paint.getFontMetricsInt().descent;
        } else if (mVerticalAlignment == ALIGN_CENTER) {
            transY -= (fontHeight - rect.height()) / 2;
        } else if (mVerticalAlignment == ALIGN_TOP) {
            transY -= fontHeight - rect.height();
        }
    } else {
        if (mVerticalAlignment == ALIGN_BASELINE) {
            transY -= paint.getFontMetricsInt().descent;
        }
    }
    canvas.translate(x, transY);
    d.draw(canvas);
    canvas.restore();
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:27,代码来源:SpannableStringUtils.java

示例3: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
    public void draw(Canvas canvas, CharSequence text, int start, int end,
                     float x, int top, int y, int bottom, Paint paint) {
        if (mVerticalAlignment == ALIGN_MIDDLE) {
            Drawable d = getDrawable();
            canvas.save();

//            // 注意如果这样实现会有问题:TextView 有 lineSpacing 时,这里 bottom 偏大,导致偏下
//            int transY = bottom - d.getBounds().bottom; // 底对齐
//            transY -= (paint.getFontMetricsInt().bottom - paint.getFontMetricsInt().top) / 2 - d.getBounds().bottom / 2; // 居中对齐
//            canvas.translate(x, transY);
//            d.draw(canvas);
//            canvas.restore();

            Paint.FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
            int fontTop = y + fontMetricsInt.top;
            int fontMetricsHeight = fontMetricsInt.bottom - fontMetricsInt.top;
            int iconHeight = d.getBounds().bottom - d.getBounds().top;
            int iconTop = fontTop + (fontMetricsHeight - iconHeight) / 2;
            canvas.translate(x, iconTop);
            d.draw(canvas);
            canvas.restore();
        } else {
            super.draw(canvas, text, start, end, x, top, y, bottom, paint);
        }
    }
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:27,代码来源:QMUIAlignMiddleImageSpan.java

示例4: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end,
                 float x, int top, int y, int bottom, Paint paint) {

    Drawable drawable = getDrawable();
    canvas.save();

    int length = 0;
    int dy = bottom - drawable.getBounds().bottom + mPadding;
    if(mVerticalAlignment == ALIGN_BASELINE) {
        length = text.length();
    }

    for(int i = 0 ; i < length ; i++) {
        if (!(Character.isLetterOrDigit(text.charAt(i)))) {
            continue;
        }
        dy -= paint.getFontMetricsInt().descent;
        canvas.translate(x, dy);
        drawable.draw(canvas);
        canvas.restore();
        return ;
    }
}
 
开发者ID:NewCasino,项目名称:browser,代码行数:25,代码来源:VerticalImageSpan.java

示例5: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
    public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
//        return super.getSize(paint, text, start, end, fm);

        // fm 以 Paint 的 fm 为基准,避免 Span 改变了 fm 导致文字行高变化 -- chant
        Drawable d = getCachedDrawable();
        Rect rect = d.getBounds();

        if (fm != null) {
            Paint.FontMetricsInt pfm = paint.getFontMetricsInt();
            // keep it the same as paint's fm
            fm.ascent = pfm.ascent;
            fm.descent = pfm.descent;
            fm.top = pfm.top;
            fm.bottom = pfm.bottom;
        }

        return rect.right;
    }
 
开发者ID:coopese,项目名称:qmui,代码行数:20,代码来源:EmojiconSpan.java

示例6: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y,
                 int bottom, Paint paint) {
    final String s = text.toString();
    String subS = s.substring(start, end);
    if (ELLIPSIS_NORMAL[0] == subS.charAt(0)
            || ELLIPSIS_TWO_DOTS[0] == subS.charAt(0)) {
        canvas.save();
        canvas.drawText(subS, x, y, paint);
        canvas.restore();
    } else {
        Drawable d = getCachedDrawable(paint);
        canvas.save();
        int transY;
        Paint.FontMetricsInt fontMetrics = new Paint.FontMetricsInt();
        paint.getFontMetricsInt(fontMetrics);
        transY = y + fontMetrics.ascent;
        canvas.translate(x, transY);
        d.draw(canvas);
        canvas.restore();
    }
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:23,代码来源:ImageSpanAlignCenter.java

示例7: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end,
                   @Nullable Paint.FontMetricsInt fm) {

    /* update FontMetricsInt or otherwise span does not get drawn when
       it covers the whole text */
    Paint.FontMetricsInt metrics = paint.getFontMetricsInt();
    if (fm != null) {
        fm.top = metrics.top;
        fm.ascent = metrics.ascent;
        fm.descent = metrics.descent;
        fm.bottom = metrics.bottom;
    }

    return (int) (paint.getTextSize()*1.2);
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:17,代码来源:CustomEmojiHelper.java

示例8: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text,
                   int start, int end,
                   Paint.FontMetricsInt fm) {
    Drawable d = getCachedDrawable(paint);
    Rect rect = d.getBounds();

    if (fm != null) {
        Paint.FontMetricsInt fontMetrics = new Paint.FontMetricsInt();
        paint.getFontMetricsInt(fontMetrics);

        fm.ascent = fontMetrics.ascent;
        fm.descent = fontMetrics.descent;

        fm.top = fontMetrics.top;
        fm.bottom = fontMetrics.bottom;
    }
    return rect.right;
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:20,代码来源:ImageSpanAlignCenter.java

示例9: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void draw(
    Canvas canvas,
    CharSequence text,
    int start,
    int end,
    float x,
    int top,
    int y,
    int bottom,
    Paint paint) {
  if (mRequestHelper == null) {
    return;
  }

  Bitmap bitmap = mRequestHelper.getBitmap();
  if (bitmap == null) {
    return;
  }

  float bottomFloat = (float) bottom - paint.getFontMetricsInt().descent;
  TMP_RECT.set(x, bottomFloat - mHeight, x + mWidth, bottomFloat);

  canvas.drawBitmap(bitmap, null, TMP_RECT, paint);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:26,代码来源:InlineImageSpanWithPipeline.java

示例10: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
    mPaint = new Paint(paint);
    mPaint.setTextSize(mTextSize);
    if(mTextSize > paint.getTextSize() && fm != null){
        Paint.FontMetricsInt newFm = mPaint.getFontMetricsInt();
        fm.descent = newFm.descent;
        fm.ascent = newFm.ascent;
        fm.top = newFm.top;
        fm.bottom = newFm.bottom;
    }
    return (int) mPaint.measureText(text, start, end);
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:14,代码来源:QMUITextSizeSpan.java

示例11: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
    if (fm != null && !QMUIDeviceHelper.isMeizu()) {
        //return后宽度为0,因此实际空隙和段落开始在同一行,需要加上一行的高度
        fm.ascent = fm.top = -mHeight - paint.getFontMetricsInt(fm);
        fm.descent = fm.bottom = 0;
    }
    return 0;
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:10,代码来源:QMUIBlockSpaceSpan.java

示例12: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, FontMetricsInt fm) {
    fm = fm == null ? paint.getFontMetricsInt() : fm;
    int iconSize = fm.bottom - fm.top;
    mDrawable.setBounds(0, 0, iconSize, iconSize);
    return super.getSize(paint, text, start, end, fm);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:8,代码来源:TintedDrawableSpan.java

示例13: drawCircle

import android.graphics.Paint; //导入方法依赖的package包/类
private void drawCircle(Canvas canvas) {
    Paint textPaint = new Paint();
    textPaint.setColor(this.mCircleWhite);
    textPaint.setAntiAlias(true);
    textPaint.setTextSize(getResources().getDimension(R.dimen.out_indicator_size));
    float textHeight = (float) ViewUtils.getTextHeight(textPaint);
    float perAngle = 270.0f / (this.mEndIndicator - this.mStartIndicator);
    int radius = (int) (((float) getViewRadius()) - (2.6f * ((float) this.mDividerWidth)));
    FontMetricsInt fmi = textPaint.getFontMetricsInt();
    float textRadius = (float) (radius - (Math.abs(fmi.bottom + fmi.top) / 2));
    RectF oval = new RectF((float) (getCenterX() - radius), (float) (getCenterY() - radius),
            (float) (getCenterX() + radius), (float) (getCenterY() + radius));
    Path path = new Path();
    path.addCircle((float) getCenterX(), (float) getCenterY(), textRadius, Direction.CW);
    Paint circlePaint = new Paint();
    circlePaint.setAntiAlias(true);
    circlePaint.setStrokeWidth(16.0f + textHeight);
    circlePaint.setStyle(Style.STROKE);
    if (this.mDividerIndicator.size() == 0) {
        circlePaint.setStrokeCap(Cap.ROUND);
        circlePaint.setColor(this.mCircleGray);
        canvas.drawArc(oval, 135.0f, 270.0f, false, circlePaint);
        return;
    }
    circlePaint.setStrokeCap(Cap.ROUND);
    drawCircleContent(canvas, (IndicatorItem) this.mDividerIndicator.get(0), oval, perAngle,
            textRadius, path, textPaint, circlePaint);
    Canvas canvas2 = canvas;
    drawCircleContent(canvas2, (IndicatorItem) this.mDividerIndicator.get(this
            .mDividerIndicator.size() - 1), oval, perAngle, textRadius, path, textPaint,
            circlePaint);
    circlePaint.setStrokeCap(Cap.BUTT);
    for (int i = 1; i < this.mDividerIndicator.size() - 1; i++) {
        drawCircleContent(canvas, (IndicatorItem) this.mDividerIndicator.get(i), oval,
                perAngle, textRadius, path, textPaint, circlePaint);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:38,代码来源:CircleIndicator.java

示例14: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
    float height = bottom - top;
    float textHeight = height * textSizeRatio;
    float minus = (height - textHeight) / 2;
    RectF rect = new RectF(x, top + minus, x + measureText(paint, text, start, end), bottom - minus);
    paint.setColor(bgColor);
    canvas.drawRect(rect, paint);

    paint.setColor(textColor);
    Paint.FontMetricsInt fm = paint.getFontMetricsInt();
    canvas.drawText(text, start, end,
            x, y - ((y + fm.ascent + y + fm.descent) / 2 - (bottom + top) / 2), paint);
}
 
开发者ID:by-syk,项目名称:TextTag,代码行数:15,代码来源:TextTagSpan.java

示例15: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
    Drawable b = getDrawable();
    canvas.save();

    int transY = bottom - b.getBounds().bottom;
    if (mVerticalAlignment == ALIGN_BASELINE) {
        transY -= paint.getFontMetricsInt().descent;
    }

    canvas.translate(x, transY);
    b.draw(canvas);
    canvas.restore();

}
 
开发者ID:DyncKathline,项目名称:LiveGiftLayout,代码行数:16,代码来源:AnimatedImageSpan.java


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