當前位置: 首頁>>代碼示例>>Java>>正文


Java Paint.getFontMetrics方法代碼示例

本文整理匯總了Java中android.graphics.Paint.getFontMetrics方法的典型用法代碼示例。如果您正苦於以下問題:Java Paint.getFontMetrics方法的具體用法?Java Paint.getFontMetrics怎麽用?Java Paint.getFontMetrics使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.Paint的用法示例。


在下文中一共展示了Paint.getFontMetrics方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: draw

import android.graphics.Paint; //導入方法依賴的package包/類
@Override
public void draw(final Canvas canvas, final CharSequence text, final int start,
                 final int end, final float x, final int top, final int y,
                 final int bottom, final Paint paint) {
    final Drawable drawable = getDrawable();
    if (drawable == null) return;
    final Paint.FontMetrics paintFontMetrics = paint.getFontMetrics();
    final float fontHeight = paintFontMetrics.descent - paintFontMetrics.ascent;
    final float centerY = y + paintFontMetrics.descent - fontHeight / 2;
    final float transitionY = centerY - textSize / 2;

    canvas.save();
    canvas.translate(x, transitionY);
    drawable.draw(canvas);
    canvas.restore();
}
 
開發者ID:hoanganhtuan95ptit,項目名稱:GifEmoji,代碼行數:17,代碼來源:EmoticonSpan.java

示例3: 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 - textSize / 2);
        fontMetrics.top = fontMetrics.ascent;
        fontMetrics.bottom = (int) (centerY + textSize / 2);
        fontMetrics.descent = fontMetrics.bottom;
    }

    return textSize;
}
 
開發者ID:hoanganhtuan95ptit,項目名稱:GifEmoticon,代碼行數:17,代碼來源:EmoticonSpan.java

示例4: getSize

import android.graphics.Paint; //導入方法依賴的package包/類
@Override
public int getSize(@NonNull Paint paint, CharSequence text,
                   int start, int end,
                   Paint.FontMetricsInt fm) {
    Drawable d = getCachedDrawable();
    Rect rect = d.getBounds();
    final int fontHeight = (int) (paint.getFontMetrics().descent - paint.getFontMetrics().ascent);
    if (fm != null) { // this is the fucking code which I waste 3 days
        if (rect.height() > fontHeight) {
            if (mVerticalAlignment == ALIGN_TOP) {
                fm.descent += rect.height() - fontHeight;
            } else if (mVerticalAlignment == ALIGN_CENTER) {
                fm.ascent -= (rect.height() - fontHeight) / 2;
                fm.descent += (rect.height() - fontHeight) / 2;
            } else {
                fm.ascent -= rect.height() - fontHeight;
            }
        }
    }
    return rect.right;
}
 
開發者ID:pan2yong22,項目名稱:AndroidUtilCode-master,代碼行數:22,代碼來源:SpanUtils.java

示例5: generateDefaultAvatar

import android.graphics.Paint; //導入方法依賴的package包/類
public static String generateDefaultAvatar(String username, String userid) {
    String s = null;
    if (!TextUtils.isEmpty(username)) {
        s = String.valueOf(username.charAt(0));
    }
    if (s == null) {
        s = "A";
    }
    String color = getColorRGB(userid);
    String string = getAllFirstLetter(username);
    createDir(SAVEADDRESS);
    File f = new File(SAVEADDRESS, string + "_" + userid);
    if (f.exists()) {
        return SCHEMA + f.getPath();
    }
    Paint paint = new Paint();
    paint.setColor(Color.WHITE);
    paint.setTextSize(220);
    paint.setAntiAlias(true);
    int width = 480;
    int height = 480;
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(Color.parseColor(color));
    Rect rect = new Rect();
    paint.getTextBounds(s, 0, s.length(), rect);
    Paint.FontMetrics fm = paint.getFontMetrics();
    int textLeft = (int) ((width - paint.measureText(s)) / 2);
    int textTop = (int) (height - width / 2 + Math.abs(fm.ascent) / 2 - 25);
    canvas.drawText(s, textLeft, textTop, paint);
    return saveBitmap(bitmap, string + "_" + userid);
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:33,代碼來源:RongGenerate.java

示例6: generateDefaultAvatar

import android.graphics.Paint; //導入方法依賴的package包/類
public static String generateDefaultAvatar(String username, String userid) {

        String s = null;
        if (!TextUtils.isEmpty(username)) {
            s = String.valueOf(username.charAt(0));
        }
        if (s == null) {
            s = "A";
        }
        String color = getColorRGB(userid);
        String string = getAllFirstLetter(username);
        createDir(SAVEADDRESS);
        File f = new File(SAVEADDRESS, string + "_" + userid);
        if (f.exists()) {
            return SCHEMA + f.getPath();
        }
        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        paint.setTextSize(220);
        paint.setAntiAlias(true);
        int width = 480;
        int height = 480;
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawColor(Color.parseColor(color));
        Rect rect = new Rect();
        paint.getTextBounds(s, 0, s.length(), rect);
        Paint.FontMetrics fm = paint.getFontMetrics();
        int textLeft = (int) ((width - paint.measureText(s)) / 2);
        int textTop = (int) (height - width / 2 + Math.abs(fm.ascent) / 2 - 25);
        canvas.drawText(s, textLeft, textTop, paint);
        return saveBitmap(bitmap, string + "_" + userid);
    }
 
開發者ID:zqHero,項目名稱:rongyunDemo,代碼行數:34,代碼來源:RongGenerate.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:h4h13,項目名稱:RetroMusicPlayer,代碼行數:13,代碼來源:BottomNavigationViewEx.java

示例8: getCacheHeight

import android.graphics.Paint; //導入方法依賴的package包/類
protected Float getCacheHeight(BaseDanmaku danmaku, Paint paint) {
    Float textSize = paint.getTextSize();
    Float textHeight = sTextHeightCache.get(textSize);
    if (textHeight == null) {
        Paint.FontMetrics fontMetrics = paint.getFontMetrics();
        textHeight = fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading;
        sTextHeightCache.put(textSize, textHeight);
    }
    return textHeight;
}
 
開發者ID:lisnstatic,項目名稱:live_master,代碼行數:11,代碼來源:SimpleTextCacheStuffer.java

示例9: calculateTextHeight

import android.graphics.Paint; //導入方法依賴的package包/類
/**
 * Calculates the height of a given string at a specific text size.
 */
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:enricocid,項目名稱:LaunchEnr,代碼行數:10,代碼來源:Utilities.java

示例10: getFontHeight

import android.graphics.Paint; //導入方法依賴的package包/類
/**
 * 返回字體高度
 * 
 * @param textSize
 * @return
 */
public static int getFontHeight(float textSize)
{
	Paint paint = new Paint();
	paint.setTextSize(textSize);
	FontMetrics fm = paint.getFontMetrics();

	return (int) Math.ceil(fm.descent - fm.top) + 2;
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:15,代碼來源:ViewUtils.java

示例11: getFontHeight

import android.graphics.Paint; //導入方法依賴的package包/類
/**
 * 獲取字體的高度
 * @param fontSize
 * @return
 */
private int getFontHeight(float fontSize){  
     Paint paint = new Paint();  
     paint.setTextSize(fontSize);  
     FontMetrics fm = paint.getFontMetrics();  
    return (int) Math.ceil(fm.descent - fm.top) + 2;  
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:12,代碼來源:SliderView.java

示例12: getFontHeight

import android.graphics.Paint; //導入方法依賴的package包/類
/**
 * 返回字體高度
 * 
 * @param textSize
 * @return
 */
public int getFontHeight(float textSize)
{
	Paint paint = new Paint();
	paint.setTextSize(textSize);
	FontMetrics fm = paint.getFontMetrics();
	
	return (int) Math.ceil(fm.descent - fm.top) + 2;
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:15,代碼來源:SingleLineEditText.java

示例13: getLineHeight

import android.graphics.Paint; //導入方法依賴的package包/類
public static float getLineHeight(Paint paint, Paint.FontMetrics fontMetrics){
    paint.getFontMetrics(fontMetrics);
    return fontMetrics.descent - fontMetrics.ascent;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:5,代碼來源:Utils.java

示例14: getLineSpacing

import android.graphics.Paint; //導入方法依賴的package包/類
public static float getLineSpacing(Paint paint, Paint.FontMetrics fontMetrics){
    paint.getFontMetrics(fontMetrics);
    return fontMetrics.ascent - fontMetrics.top + fontMetrics.bottom;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:5,代碼來源:Utils.java

示例15: getFontHeight

import android.graphics.Paint; //導入方法依賴的package包/類
/**
 * @return 返回指定筆的文字高度
 */
private float getFontHeight(Paint paint) {
	FontMetrics fm = paint.getFontMetrics();
	return fm.descent - fm.ascent;
}
 
開發者ID:smartbeng,項目名稱:PaoMovie,代碼行數:8,代碼來源:RangeSeekBar.java


注:本文中的android.graphics.Paint.getFontMetrics方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。