當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。