当前位置: 首页>>代码示例>>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;未经允许,请勿转载。