當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。