本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例13: getLineHeight
import android.graphics.Paint; //导入方法依赖的package包/类
public static float getLineHeight(Paint paint, Paint.FontMetrics fontMetrics){
paint.getFontMetrics(fontMetrics);
return fontMetrics.descent - fontMetrics.ascent;
}
示例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;
}
示例15: getFontHeight
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* @return 返回指定笔的文字高度
*/
private float getFontHeight(Paint paint) {
FontMetrics fm = paint.getFontMetrics();
return fm.descent - fm.ascent;
}