本文整理匯總了Java中android.graphics.Paint.FontMetrics類的典型用法代碼示例。如果您正苦於以下問題:Java FontMetrics類的具體用法?Java FontMetrics怎麽用?Java FontMetrics使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FontMetrics類屬於android.graphics.Paint包,在下文中一共展示了FontMetrics類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fontSizeCompare
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
private int fontSizeCompare(float sizeDp, int cols, int rows, int width, int height) {
// read new metrics to get exact pixel dimensions
defaultPaint.setTextSize((int) (sizeDp * this.displayDensity + 0.5f));
FontMetrics fm = defaultPaint.getFontMetrics();
float[] widths = new float[1];
defaultPaint.getTextWidths("X", widths);
int termWidth = (int) widths[0] * cols;
int termHeight = (int) Math.ceil(fm.descent - fm.top) * rows;
Log.d("fontsize", String.format("font size %fdp resulted in %d x %d", sizeDp, termWidth, termHeight));
// Check to see if it fits in resolution specified.
if (termWidth > width || termHeight > height)
return 1;
if (termWidth == width || termHeight == height)
return 0;
return -1;
}
示例2: RoundedIconGenerator
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
/**
* Constructs the generator and initializes the common members ignoring display density.
*
* @param iconWidthPx The width of the generated icon in pixels.
* @param iconHeightPx The height of the generated icon in pixels.
* @param cornerRadiusPx The radius of the corners in the icon in pixels.
* @param backgroundColor Color at which the rounded rectangle should be drawn.
* @param textSizePx Size at which the text should be drawn in pixels.
*/
public RoundedIconGenerator(int iconWidthPx, int iconHeightPx, int cornerRadiusPx,
int backgroundColor, float textSizePx) {
mIconWidthPx = iconWidthPx;
mIconHeightPx = iconHeightPx;
mCornerRadiusPx = cornerRadiusPx;
mBackgroundRect = new RectF(0, 0, mIconWidthPx, mIconHeightPx);
mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBackgroundPaint.setColor(backgroundColor);
mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setColor(Color.WHITE);
mTextPaint.setFakeBoldText(true);
mTextPaint.setTextSize(textSizePx);
FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
mTextYOffset = -textFontMetrics.top;
}
示例3: init
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
private void init(){
mWidth = (int) getPaint().measureText(getText().toString());
FontMetrics fm = getPaint().getFontMetrics();
mFontHeiht = (float)Math.ceil(fm.descent - fm.ascent);
int horizontalPadding = getHorizontalPaddint();
int verticalPadding = getVerticalPaddint();
mPath.reset();
mPath.moveTo(0, 0);
mPath.lineTo(mWidth + horizontalPadding, 0);
mPath.lineTo(mWidth + horizontalPadding, mFontHeiht + verticalPadding);
mPath.lineTo(25, mFontHeiht + verticalPadding);
mPath.lineTo(0, mFontHeiht+verticalPadding+25);
mPath.close();
mPaint.setAntiAlias(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Style.FILL);
getPaint().setColor(Color.WHITE);// 不知道什麽原因,xml設置無效。暫時先在代碼中設置。
}
示例4: TitleBar
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
public TitleBar(Context context)
{
super(context);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.sys_title_bg_vertical, opts);
height = opts.outHeight;
setBackgroundResource(R.drawable.sys_title_bg_vertical);
paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setTextSize(24);
FontMetrics fm = paint.getFontMetrics();
yPostion = (height - fm.descent + fm.ascent) / 2 - fm.ascent;
mBusyIndicator = new ProgressBar(getContext());
mBusyIndicator.setIndeterminate(true);
//mBusyIndicator.setBackgroundResource(R.drawable.busy);
addView(mBusyIndicator);
mBusyIndicator.setVisibility(GONE);
}
示例5: fontSizeCompare
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
private int fontSizeCompare(float size, int cols, int rows, int width, int height) {
// read new metrics to get exact pixel dimensions
defaultPaint.setTextSize(size);
FontMetrics fm = defaultPaint.getFontMetrics();
float[] widths = new float[1];
defaultPaint.getTextWidths("X", widths);
int termWidth = (int)widths[0] * cols;
int termHeight = (int)Math.ceil(fm.descent - fm.top) * rows;
Log.d("fontsize", String.format("font size %f resulted in %d x %d", size, termWidth, termHeight));
// Check to see if it fits in resolution specified.
if (termWidth > width || termHeight > height)
return 1;
if (termWidth == width || termHeight == height)
return 0;
return -1;
}
示例6: drawText
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
/**
* 描述:繪製文本,支持換行.
*
* @param canvas the canvas
* @param text the text
* @param maxWPix the max w pix
* @param paint the paint
* @param left the left
* @param top the top
* @return the int
*/
public static int drawText(Canvas canvas,String text,int maxWPix,TextPaint paint,int left,int top) {
if(AbStrUtil.isEmpty(text)){
return 1;
}
//需要根據文字長度控製換行
//測量文字的長度
List<String> mStrList = getDrawRowStr(text,maxWPix,paint);
FontMetrics fm = paint.getFontMetrics();
int hSize = (int)Math.ceil(fm.descent - fm.ascent)+2;
for(int i=0;i<mStrList.size();i++){
//計算坐標
int x = left;
int y = top+hSize/2+hSize*i;
String textLine = mStrList.get(i);
canvas.drawText(textLine,x,y, paint);
}
return mStrList.size();
}
示例7: init
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
private void init(){
mWidth = (int) getPaint().measureText(getText().toString());
FontMetrics fm = getPaint().getFontMetrics();
mFontHeiht = (float)Math.ceil(fm.descent - fm.ascent);
int horizontalPadding = getHorizontalPaddint();
int verticalPadding = getVerticalPaddint();
mPath.reset();
mPath.moveTo(0, 0);
mPath.lineTo(mWidth + horizontalPadding, 0);
mPath.lineTo(mWidth + horizontalPadding, mFontHeiht + verticalPadding);
mPath.lineTo(25, mFontHeiht + verticalPadding);
mPath.lineTo(0, mFontHeiht+verticalPadding+25);
mPath.close();
mPaint.setAntiAlias(true);
mPaint.setColor(ResFinder.getColor("umeng_comm_topic_tip_bg"));
mPaint.setStyle(Style.FILL);
getPaint().setColor(Color.WHITE);// 不知道什麽原因,xml設置無效。暫時先在代碼中設置。
}
示例8: drawText
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
/**
* Draw text.
*
* @param canvas the canvas
* @param text the text
* @param maxWPix the max w pix
* @param paint the paint
* @return the int
*/
public int drawText(Canvas canvas, String text, int maxWPix,
TextPaint paint) {
if (TextUtils.isEmpty(text)) {
return 1;
}
// 需要根據文字長度控製換行
// 測量文字的長度
List<String> mStrList = getDrawRowStr(text, maxWPix, paint);
FontMetrics fm = paint.getFontMetrics();
int hSize = (int)Math.ceil(fm.descent - fm.ascent);
for (int i = 0; i < mStrList.size(); i++) {
// 計算坐標
float x = leftPadding;
float y = topPadding+hSize/2+i*(hSize+lineSpacing)+bottomPadding;
String textLine = mStrList.get(i);
if(i < maxLines){
canvas.drawText(textLine, x, y, paint);
}
}
return mStrList.size();
}
示例9: drawLabel
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
protected void drawLabel(Canvas canvas, String labelText, List<RectF> prevLabelsBounds, int centerX, int centerY,
float shortRadius, float longRadius, float currentAngle, float angle, int left, int right, int color,
Paint paint, boolean line, boolean showMoreLabel)
{
LabelPoint labelPoint =
drawLabelHandler(canvas, labelText, prevLabelsBounds, centerX, centerY, shortRadius, longRadius,
currentAngle, angle, left, right, color, paint, line);
String[] texts = labelText.split("/");
for (int index = 0; index < texts.length; index++)
{
canvas.drawText(texts[index], labelPoint.xLabel, labelPoint.yLabel, paint);
FontMetrics fm = paint.getFontMetrics();
labelPoint.yLabel = labelPoint.yLabel + Math.round(fm.descent - fm.top) + 2;
}
if (line)
{
prevLabelsBounds.add(new RectF(labelPoint.xLabel, labelPoint.yLabel, labelPoint.xLabel
+ labelPoint.widthLabel, labelPoint.yLabel + labelPoint.size));
}
}
示例10: dispatchDraw
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
/**
* @see android.view.ViewGroup#dispatchDraw(Canvas)
*/
@Override
protected void dispatchDraw(Canvas canvas) {
if (mState == STATE_REFRESHING) {
//
// float centerX = mArrowImageView.getMeasuredWidth() / 2;
// float centerY = mArrowImageView.getMeasuredHeight() / 2;
// Matrix matrix = mArrowImageView.getImageMatrix();
// mArrowImageView.setScaleType(ScaleType.MATRIX);
// matrix.postRotate(25, centerX, centerY);
// mArrowImageView.setImageMatrix(matrix);
}
super.dispatchDraw(canvas);
if (isInEditMode()) {
return;
}
FontMetrics fontMetrics = mPaint.getFontMetrics();
// 計算文字高度
float fontHeight = fontMetrics.bottom - fontMetrics.top;
// 計算文字baseline
float textBaseY = getHeight() - (getHeight() - fontHeight) / 2 - fontMetrics.bottom;
canvas.drawText(mstrTitle, getWidth() / 2 + mArrowImageView.getMeasuredWidth(), textBaseY, mPaint);
}
示例11: drawLabel
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
/**
* 畫左右的Label
*
* @param canvas
*/
private void drawLabel(Canvas canvas) {
canvas.save();
int vh = getHeight();
FontMetrics fontMetrics = paint.getFontMetrics();
// 計算文字高度
float fontHeight = fontMetrics.bottom - fontMetrics.top;
// 計算文字baseline
float y = PADDING + vh - (vh - fontHeight) / 2 - fontMetrics.bottom;
if (!TextUtils.isEmpty(mRightLabel)) {
canvas.drawText(mRightLabel, getWidth() - rightLabelLen / 2
- PADDING, y, labelPaint);
}
if (!TextUtils.isEmpty(mLeftLabel)) {
canvas.drawText(mLeftLabel, PADDING + leftLabelLen / 2, y,
labelPaint);
}
canvas.restore();
}
示例12: initVariable
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
private void initVariable() {
mCirclePaint = new Paint();
mCirclePaint.setAntiAlias(true);
mCirclePaint.setColor(mCircleColor);
mCirclePaint.setStyle(Paint.Style.FILL);
mRingPaint = new Paint();
mRingPaint.setAntiAlias(true);
mRingPaint.setColor(mRingColor);
mRingPaint.setStyle(Paint.Style.STROKE);
mRingPaint.setStrokeWidth(mStrokeWidth);
mTextPaint = new Paint();
mTextPaint.setAntiAlias(true);
mTextPaint.setStyle(Paint.Style.FILL);
mTextPaint.setARGB(255, 255, 255, 255);
mTextPaint.setTextSize(mRadius / 2);
FontMetrics fm = mTextPaint.getFontMetrics();
mTxtHeight = (int) Math.ceil(fm.descent - fm.ascent);
}
示例13: onDraw
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
protected void onDraw(Canvas canvas){
Paint paint = new Paint();
paint.setStyle(Style.STROKE);
paint.setAntiAlias(true);
paint.setColor(0xffe9e9e9);
paint.setTextSize(Function.getFitPx(getContext(), 30));
FontMetrics fm = paint.getFontMetrics();
// canvas.drawRect(drawRect, paint);
canvas.drawLine(drawRect.left, drawRect.top, drawRect.right, drawRect.top, paint);
canvas.drawLine(drawRect.left, drawRect.bottom, drawRect.right, drawRect.bottom, paint);
float h = (maxValue - minValue) / 2;
float y = Function.getYCoordinate(drawRect, minValue+h, maxValue, minValue);
paint.setColor(0xffbbbbbc);
canvas.drawLine(drawRect.left, y, drawRect.right, y, paint);
paint.setTextAlign(Align.RIGHT);
int baseline = (int) (drawRect.top + (drawRect.bottom - drawRect.top - fm.bottom + fm.top) / 2 - fm.top);
canvas.drawText("0%", drawRect.left-Function.getFitPx(getContext(), 20), baseline, paint);
paint.setColor(getContext().getResources().getColor(R.color.font_de3031));
canvas.drawText("3.4%", drawRect.left-Function.getFitPx(getContext(), 20), drawRect.top-(fm.top-fm.bottom)/2 + 2, paint);
paint.setColor(getContext().getResources().getColor(R.color.font_32a632));
canvas.drawText("-3.4%", drawRect.left-Function.getFitPx(getContext(), 20), drawRect.bottom, paint);
}
示例14: onDraw
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
@Override
protected void onDraw(Canvas canvas)
{
Paint mPaint = getPaint();
//Get font's height & leading:
FontMetrics fm = mPaint.getFontMetrics();
float height = fm.descent - fm.ascent + fm.leading;
float x = 0;
float y = height;
String[] textLines = autoSplit(getText().toString(), mPaint, getWidth());
for (String textLine : textLines)
{
canvas.drawText(textLine, x, y, mPaint);
y += height;
}
}
示例15: setFontSize
import android.graphics.Paint.FontMetrics; //導入依賴的package包/類
/**
* Request a different font size. Will make call to parentChanged() to make
* sure we resize PTY if needed.
*
* @param sizeDp Size of font in dp
*/
private final void setFontSize(float sizeDp) {
if (sizeDp <= 0.0) {
return;
}
final int fontSizePx = (int) (sizeDp * this.displayDensity + 0.5f);
defaultPaint.setTextSize(fontSizePx);
fontSizeDp = sizeDp;
// read new metrics to get exact pixel dimensions
FontMetrics fm = defaultPaint.getFontMetrics();
charTop = (int) Math.ceil(fm.top);
float[] widths = new float[1];
defaultPaint.getTextWidths("X", widths);
charWidth = (int) Math.ceil(widths[0]);
charHeight = (int) Math.ceil(fm.descent - fm.top);
// refresh any bitmap with new font size
if (parent != null) {
parentChanged(parent);
}
for (FontSizeChangedListener ofscl : fontSizeChangedListeners) {
ofscl.onFontSizeChanged(sizeDp);
}
host.setFontSize((int) sizeDp);
manager.hostdb.saveHost(host);
forcedSize = false;
}