当前位置: 首页>>代码示例>>Java>>正文


Java Paint.measureText方法代码示例

本文整理汇总了Java中android.graphics.Paint.measureText方法的典型用法代码示例。如果您正苦于以下问题:Java Paint.measureText方法的具体用法?Java Paint.measureText怎么用?Java Paint.measureText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Paint的用法示例。


在下文中一共展示了Paint.measureText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end,
                   @Nullable Paint.FontMetricsInt fm) {
    paint.getTextWidths(MEASURE_NUMBER_CHARS, mNumberWidths);
    float mw = 0.f;
    char ld = '0';
    for (int i = MEASURE_NUMBER_CHARS.length() - 1; i >= 0; --i) {
        if (mNumberWidths[i] > mw) {
            mNumberWidths[i] = mw;
            ld = MEASURE_NUMBER_CHARS.charAt(i);
        }
    }
    CharSequence s = text.subSequence(start - mPreOffset, start);
    String rs = sMatchNumbersRegex.matcher(s).replaceAll(String.valueOf(ld));
    return (int) (paint.measureText(rs) - paint.measureText(s, 0, s.length()));
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:17,代码来源:FixedWidthTimestampSpan.java

示例2: getLabelBitmap

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 *
 * @param name name of the zone
 * @param zoneLabelOptions appearance options for the zone label marker
 * @return Bitmap with the zone label
 */
private Bitmap getLabelBitmap(String name, ZoneLabelOptions zoneLabelOptions){
    Paint zonesLabelPaint = new Paint();
    zonesLabelPaint.setTextSize(zoneLabelOptions.getLabelSize());
    zonesLabelPaint.setColor(zoneLabelOptions.getLabelColor());
    zonesLabelPaint.setTextAlign(Paint.Align.LEFT);
    float zoneLabelBaseline = -zonesLabelPaint.ascent();

    int width = (int) (zonesLabelPaint.measureText(name) + 0.5f); // round
    int height = (int) (zoneLabelBaseline + zonesLabelPaint.descent() + 0.5f);

    Bitmap zoneLabelBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas zoneLabelCanvas = new Canvas(zoneLabelBitmap);
    zoneLabelCanvas.drawText(name, 0, zoneLabelBaseline, zonesLabelPaint);
    return zoneLabelBitmap;
}
 
开发者ID:Ubudu,项目名称:GoogleMapsLayout-Android,代码行数:22,代码来源:MapLayout.java

示例3: textAsBitmap

import android.graphics.Paint; //导入方法依赖的package包/类
/** @return a bitmap with text.*/
private static Bitmap textAsBitmap(String text, float textSize, int textColor) {

    Paint paint = new Paint();
    paint.setTextSize(textSize);
    paint.setColor(textColor);
    paint.setTextAlign(Paint.Align.LEFT);

    int width = (int) (paint.measureText(text) + 0.5f); // round
    float baseline = (int) (-paint.ascent() + 0.5f); // ascent() is negative
    int height = (int) (baseline + paint.descent() + 0.5f);

    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(image);
    canvas.drawText(text, 0, baseline, paint);

    return image;
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:20,代码来源:ImageUtils.java

示例4: layoutText

import android.graphics.Paint; //导入方法依赖的package包/类
private void layoutText() {
    Paint paint = getPaint();
    if(mTextSize != 0f) paint.setTextSize(mTextSize);
    float textWidth = paint.measureText(getText().toString());
    float width = getWidth() - getPaddingLeft() - getPaddingRight();
    float textSize = getTextSize();
    if(textWidth > width) {
        paint.setTextSize(textSize * width / textWidth);
        mTextX = getPaddingLeft();
        mTextSize = textSize;
    }
    else {
        mTextX = (getWidth() - textWidth) / 2;
    }
    mTextY = (getHeight() - paint.ascent() - paint.descent()) / 2;
    if(mHintPaint != null) mHintPaint.setTextSize(paint.getTextSize() * 0.8f);
}
 
开发者ID:gigabytedevelopers,项目名称:CalcMate,代码行数:18,代码来源:ColorButton.java

示例5: createBgBitmap

import android.graphics.Paint; //导入方法依赖的package包/类
private Bitmap createBgBitmap(int w, int h, String text) {
    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(Color.WHITE);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    float textSize = 70;
    paint.setTextSize(textSize);
    int cx = w / 2;
    int cy = h / 2;
    float measureText = paint.measureText(text);
    //将文字画在中间
    canvas.drawText(text, cx - measureText / 2, cy + textSize / 2, paint);
    canvas = null;
    paint = null;
    return bitmap;
}
 
开发者ID:halohoop,项目名称:AndroidDigIn,代码行数:17,代码来源:EraserView_SRCOUT.java

示例6: init

import android.graphics.Paint; //导入方法依赖的package包/类
private void init(Context context) {

        rectF_pb = new RectF();

        // paint
        paint_pb = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint_pb.setColor(Color.GREEN);

        paint_txt = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint_txt.setTextSize(dipToPx(15));
        paint_txt.setColor(Color.BLACK);

        Paint.FontMetrics fm = paint_txt.getFontMetrics();
        txtHeight = Math.abs(fm.ascent) + Math.abs(fm.descent);
        txtWidth = paint_txt.measureText("100%");
    }
 
开发者ID:linheimx,项目名称:BackgroundProgress,代码行数:17,代码来源:BackgroundProgressView.java

示例7: PageFactory

import android.graphics.Paint; //导入方法依赖的package包/类
public PageFactory(Context context, int width, int height, int fontSize, String bookId,
                   List<BookMixAToc.mixToc.Chapters> chaptersList) {
    mContext = context;
    mWidth = width;
    mHeight = height;
    mFontSize = fontSize;
    mLineSpace = mFontSize / 5 * 2;
    mNumFontSize = ScreenUtils.dpToPxInt(16);
    marginWidth = ScreenUtils.dpToPxInt(15);
    marginHeight = ScreenUtils.dpToPxInt(15);
    mVisibleHeight = mHeight - marginHeight * 2 - mNumFontSize * 2 - mLineSpace * 2;
    mVisibleWidth = mWidth - marginWidth * 2;
    mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace);
    rectF = new Rect(0, 0, mWidth, mHeight);

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setTextSize(mFontSize);
    mPaint.setTextSize(ContextCompat.getColor(context, R.color.chapter_content_day));
    mPaint.setColor(Color.BLACK);
    mTitlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTitlePaint.setTextSize(mNumFontSize);
    mTitlePaint.setColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.chapter_title_day));
    timeLen = (int) mTitlePaint.measureText("00:00");
    percentLen = (int) mTitlePaint.measureText("00.00%");
    // Typeface typeface = Typeface.createFromAsset(context.getAssets(),"fonts/FZBYSK.TTF");
    // mPaint.setTypeface(typeface);
    // mNumPaint.setTypeface(typeface);

    this.bookId = bookId;
    this.chaptersList = chaptersList;

    time = dateFormat.format(new Date());
}
 
开发者ID:zwmlibs,项目名称:BookReader-master,代码行数:34,代码来源:PageFactory.java

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

示例9: 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) {
//            canvas.translate(mLeftMargin, mTopMargin);
            float width = paint.measureText(text.subSequence(start, end).toString());
            float newBottom = bottom - 2;   // magic number to make sure consecutive lines don't touch
            RectF rect = new RectF(x, top, x + mLeftPadding + width + mRightPadding, newBottom);
            paint.setColor(mBackgroundColor);
            canvas.drawRoundRect(rect, mCornerRadius, mCornerRadius, paint);
            paint.setColor(mTextColor);
            canvas.drawText(text, start, end, x + mLeftPadding, y, paint);
        }
 
开发者ID:TryGhost,项目名称:Ghost-Android,代码行数:13,代码来源:ChipsEditText.java

示例10: resizeText

import android.graphics.Paint; //导入方法依赖的package包/类
public static void resizeText(TextView textView, int originalTextSize, int minTextSize) {
  final Paint paint = textView.getPaint();
  final int width = textView.getWidth();
  if (width == 0) {
    return;
  }
  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalTextSize);
  float ratio = width / paint.measureText(textView.getText().toString());
  if (ratio <= 1.0f) {
    textView.setTextSize(
        TypedValue.COMPLEX_UNIT_PX, Math.max(minTextSize, originalTextSize * ratio));
  }
}
 
开发者ID:dialogs,项目名称:android-dialer,代码行数:14,代码来源:ViewUtil.java

示例11: getTextSize

import android.graphics.Paint; //导入方法依赖的package包/类
private static final float[] getTextSize(String str, Paint paint) {
    float[] out = new float[2];
    Rect boundaries = new Rect();
    paint.getTextBounds(str, 0, str.length(), boundaries);

    out[0] = paint.measureText(str);
    out[1] = boundaries.height();
    return out;
}
 
开发者ID:PacktPublishing,项目名称:Building-Android-UIs-with-Custom-Views,代码行数:10,代码来源:PrimitiveDrawer.java

示例12: drawLeadingMargin

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) {

    // if there was a line break, we don't need to draw anything
    if (!first
            || !LeadingMarginUtils.selfStart(start, text, this)) {
        return;
    }

    theme.applyListItemStyle(p);

    final int numberWidth = (int) (p.measureText(number) + .5F);

    // @since 1.0.3
    int width = theme.getBlockMargin();
    if (numberWidth > width) {
        width = numberWidth;
        margin = numberWidth;
    } else {
        margin = 0;
    }

    final int left;
    if (dir > 0) {
        left = x + (width * dir) - numberWidth;
    } else {
        left = x + (width * dir) + (width - numberWidth);
    }

    final float numberY = CanvasUtils.textCenterY(top, bottom, p);

    c.drawText(number, left, numberY, p);
}
 
开发者ID:noties,项目名称:Markwon,代码行数:34,代码来源:OrderedListItemSpan.java

示例13: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
    if (mAvoidSuperChangeFontMetrics) {
        Drawable d = getDrawable();
        Rect rect = d.getBounds();
        mWidth = rect.right;
    } else {
        mWidth = super.getSize(paint, text, start, end, fm);
    }
    if (mFontWidthMultiple > 0) {
        mWidth = (int) (paint.measureText("子") * mFontWidthMultiple);
    }
    return mWidth;
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:15,代码来源:QMUIAlignMiddleImageSpan.java

示例14: getFontlength

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * @return 返回指定笔和指定字符串的长度
 */
private float getFontlength(Paint paint, String str) {
	return paint.measureText(str);
}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:7,代码来源:RangeSeekBar.java

示例15: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
    int width = (int) paint.measureText(mTableLinkText, 0, mTableLinkText.length());
    mTextSize = paint.getTextSize();
    return width;
}
 
开发者ID:SysdataSpA,项目名称:SDHtmlTextView,代码行数:7,代码来源:DrawTableLinkSpan.java


注:本文中的android.graphics.Paint.measureText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。