當前位置: 首頁>>代碼示例>>Java>>正文


Java FontMetricsInt類代碼示例

本文整理匯總了Java中android.graphics.Paint.FontMetricsInt的典型用法代碼示例。如果您正苦於以下問題:Java FontMetricsInt類的具體用法?Java FontMetricsInt怎麽用?Java FontMetricsInt使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FontMetricsInt類屬於android.graphics.Paint包,在下文中一共展示了FontMetricsInt類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: drawData

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
private void drawData(Canvas canvas) {
    // Draw the selected text first, and then draw up the rest of the text.
    float scale = parabola(mViewHeight / 4.0f, mMoveLen);
    float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
    mPaint.setTextSize(size);
    mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
    // Text center drawing, pay attention to the calculation of baseline to reach the center, y value is text central coordinates.
    float x = (float) (mViewWidth / 2.0);
    float y = (float) (mViewHeight / 2.0 + mMoveLen);
    FontMetricsInt fmi = mPaint.getFontMetricsInt();
    float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));

    canvas.drawText(mDataList.get(mCurrentSelected), x, baseline, mPaint);
    // Draw the top data.
    for (int i = 1; (mCurrentSelected - i) >= 0; i++) {
        drawOtherText(canvas, i, -1);
    }
    // Draw below data.
    for (int i = 1; (mCurrentSelected + i) < mDataList.size(); i++) {
        drawOtherText(canvas, i, 1);
    }
}
 
開發者ID:Jusenr,項目名稱:androidtools,代碼行數:23,代碼來源:DatePickerView.java

示例2: onMeasure

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  final int size = MeasureSpec.getSize(widthMeasureSpec);
  final int mode = MeasureSpec.getMode(widthMeasureSpec);
  if (!useSystemEmoji()                                            &&
      getEllipsize() == TruncateAt.END                             &&
      !TextUtils.isEmpty(source)                                   &&
      (mode == MeasureSpec.AT_MOST || mode == MeasureSpec.EXACTLY) &&
      getPaint().breakText(source, 0, source.length()-1, true, size, null) != source.length())
  {
    needsEllipsizing = true;
    FontMetricsInt font = getPaint().getFontMetricsInt();
    super.onMeasure(MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(Math.abs(font.top - font.bottom), MeasureSpec.EXACTLY));
  } else {
    needsEllipsizing = false;
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:19,代碼來源:EmojiTextView.java

示例3: getSize

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, FontMetricsInt fm) {
    Rect rect = this.getDrawable().getBounds();
    if (fm != null) {
        FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
        end = fontMetricsInt.bottom - fontMetricsInt.top;
        int var = rect.bottom - rect.top;
        start = var / 2 - end / 4;
        end = var / 2 + end / 4;
        fm.ascent = -end;
        fm.top = -end;
        fm.bottom = start;
        fm.descent = start;
    }
    return rect.right;
}
 
開發者ID:abook23,項目名稱:godlibrary,代碼行數:17,代碼來源:SpannableUtils.java

示例4: drawData

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
private void drawData(Canvas canvas) {
    // 先繪製選中的text再往上往下繪製其餘的text
    float scale = parabola(mViewHeight / 4.0f, mMoveLen);
    float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
    mPaint.setTextSize(size);
    mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
    // text居中繪製,注意baseline的計算才能達到居中,y值是text中心坐標
    float x = (float) (mViewWidth / 2.0);
    float y = (float) (mViewHeight / 2.0 + mMoveLen);
    FontMetricsInt fmi = mPaint.getFontMetricsInt();
    float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));
    if (mDataList.size() > 0) {
        canvas.drawText(mDataList.get(mCurrentSelected), x, baseline,
                mPaint);
    }
    // 繪製上方data
    for (int i = 1; (mCurrentSelected - i) >= 0; i++) {
        drawOtherText(canvas, i, -1);
    }
    // 繪製下方data
    for (int i = 1; (mCurrentSelected + i) < mDataList.size(); i++) {
        drawOtherText(canvas, i, 1);
    }
}
 
開發者ID:Horrarndoo,項目名稱:YiZhi,代碼行數:25,代碼來源:PickerView.java

示例5: drawData

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
private void drawData(Canvas canvas) {
    // 先繪製選中的text再往上往下繪製其餘的text
    float scale = parabola(mViewHeight / 4.0f, mMoveLen);
    float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
    mPaint.setTextSize(size);
    mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
    // text居中繪製,注意baseline的計算才能達到居中,y值是text中心坐標
    float x = (float) (mViewWidth / 2.0);
    float y = (float) (mViewHeight / 2.0 + mMoveLen);
    FontMetricsInt fmi = mPaint.getFontMetricsInt();
    float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));

    if (null != mItemProvider) {
        String itemData = mItemProvider.getItem(mDataList.get(mCurrentSelected), mCurrentSelected);
        canvas.drawText(itemData, x, baseline, mPaint);
    }
    // 繪製上方data
    for (int i = 1; (mCurrentSelected - i) >= 0; i++) {
        drawOtherText(canvas, i, -1);
    }
    // 繪製下方data
    for (int i = 1; (mCurrentSelected + i) < mDataList.size(); i++) {
        drawOtherText(canvas, i, 1);
    }
}
 
開發者ID:yhyzgn,項目名稱:Widgets,代碼行數:26,代碼來源:PickerView.java

示例6: drawOtherText

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
/**
 * @param canvas
 * @param position 距離mCurrentSelected的差值
 * @param type     1表示向下繪製,-1表示向上繪製
 */
private void drawOtherText(Canvas canvas, int position, int type) {
    float d = (float) (MARGIN_ALPHA * mMinTextSize * position + type * mMoveLen);
    float scale = parabola(mViewHeight / 4.0f, d);
    float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
    mPaint.setTextSize(size);
    mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
    float y = (float) (mViewHeight / 2.0 + type * d);
    FontMetricsInt fmi = mPaint.getFontMetricsInt();
    float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));

    if (null != mItemProvider) {
        int index = mCurrentSelected + type * position;
        String itemData = mItemProvider.getItem(mDataList.get(index), index);
        canvas.drawText(itemData, (float) (mViewWidth / 2.0), baseline, mPaint);
    }
}
 
開發者ID:yhyzgn,項目名稱:Widgets,代碼行數:22,代碼來源:PickerView.java

示例7: drawProgress

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
private void drawProgress(Canvas canvas) {
    Paint bgPaint = getProgressPaint();
    bgPaint.setColor(this.mIndicatorBgColor);
    canvas.drawLine(14.0f, (float) (this.mHeight / 2), (float) (this.mWidth - 14), (float)
            (this.mHeight / 2), bgPaint);
    if (this.mProgress != 0.0f) {
        Paint progressPaint = getProgressPaint();
        progressPaint.setColor(this.mIndicatorProgressColor);
        int stopX = (int) (((float) (this.mWidth - 28)) * this.mProgress);
        canvas.drawLine(14.0f, (float) (this.mHeight / 2), (float) stopX, (float) (this
                .mHeight / 2), progressPaint);
        Paint textPain = getAlertPaint();
        textPain.setTextSize((float) this.mIndicatorSize);
        textPain.setColor(this.mIndicatorTextColor);
        int textWidth = ViewUtils.getTextWidth(textPain, this.mAlert);
        Paint alertPaint = getProgressPaint();
        alertPaint.setColor(this.mIndicatorProgressColor);
        alertPaint.setStrokeWidth(78.4f);
        canvas.drawLine((float) (stopX - (textWidth / 2)), (float) (this.mHeight / 2),
                (float) ((textWidth / 2) + stopX), (float) (this.mHeight / 2), alertPaint);
        FontMetricsInt fmi = textPain.getFontMetricsInt();
        Canvas canvas2 = canvas;
        canvas2.drawText(this.mAlert, (float) (stopX - (textWidth / 2)), (float) ((this
                .mHeight / 2) + (Math.abs(fmi.bottom + fmi.top) / 2)), textPain);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:27,代碼來源:LineIndicator.java

示例8: drawData

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
private void drawData(Canvas canvas) {
    // 先繪製選中的text再往上往下繪製其餘的text
    float scale = parabola(mViewHeight / 4.0f, mMoveLen);
    float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
    mPaint.setTextSize(size);
    mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
    // text居中繪製,注意baseline的計算才能達到居中,y值是text中心坐標
    float x = (float) (mViewWidth / 2.0);
    float y = (float) (mViewHeight / 2.0 + mMoveLen);
    FontMetricsInt fmi = mPaint.getFontMetricsInt();
    float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));

    canvas.drawText(mDataList.get(mCurrentSelected), x, baseline, mPaint);
    // 繪製上方data
    for (int i = 1; (mCurrentSelected - i) >= 0; i++) {
        drawOtherText(canvas, i, -1);
    }
    // 繪製下方data
    for (int i = 1; (mCurrentSelected + i) < mDataList.size(); i++) {
        drawOtherText(canvas, i, 1);
    }
}
 
開發者ID:StickyTolt,項目名稱:ForeverLibrary,代碼行數:23,代碼來源:DatePickerView.java

示例9: getSize

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
/**
 * 代碼跟父類代碼相似,就是getCachedDrawable()替換成getDrawable(),因為前者裏麵的圖片是WeakReference,
 * 容易被gc回收,所以這裏要避免這個問題
 */
@Override
public int getSize(Paint paint, CharSequence text, int start, int end,
                   FontMetricsInt fm) {
    Drawable d = getDrawable();

    if (lineHeight > 0) {
        return (int) (d.getIntrinsicWidth() * scale);
    } else {
        Rect rect = d.getBounds();

        if (fm != null) {
            fm.ascent = -rect.bottom;
            fm.descent = 0;

            fm.top = fm.ascent;
            fm.bottom = 0;
        }
        return rect.right;

    }
}
 
開發者ID:BigAppOS,項目名稱:BigApp_Discuz_Android,代碼行數:26,代碼來源:AnimatedImageSpan.java

示例10: drawData

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
private void drawData(Canvas canvas) {
    // 先繪製選中的text再往上往下繪製其餘的text
    float scale = parabola(mViewHeight / 3.2f, mMoveLen);
    float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
    mPaint.setTextSize(size);
    mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
    // text居中繪製,注意baseline的計算才能達到居中,y值是text中心坐標
    float x = (float) (mViewWidth / 2.0);
    float y = (float) (mViewHeight / 2.0 + mMoveLen);
    FontMetricsInt fmi = mPaint.getFontMetricsInt();
    float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));

    canvas.drawText(mDataList.get(mCurrentSelected), x, baseline, mPaint);
    // 繪製上方data
    for (int i = 1; (mCurrentSelected - i) >= 0; i++) {
        drawOtherText(canvas, i, -1);
    }
    // 繪製下方data
    for (int i = 1; (mCurrentSelected + i) < mDataList.size(); i++) {
        drawOtherText(canvas, i, 1);
    }

}
 
開發者ID:woniukeji,項目名稱:jianguo,代碼行數:24,代碼來源:PickerDateView.java

示例11: drawData

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
private void drawData(Canvas canvas) {
    // 先繪製選中的text再往上往下繪製其餘的text
    float scale = parabola(mViewHeight / 4.0f, mMoveLen);
    float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
    mPaint.setTextSize(size);
    mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
    // text居中繪製,注意baseline的計算才能達到居中,y值是text中心坐標
    float x = (float) (mViewWidth / 2.0);
    float y = (float) (mViewHeight / 2.0 + mMoveLen);
    FontMetricsInt fmi = mPaint.getFontMetricsInt();
    float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));

    canvas.drawText(mDataList.get(mCurrentSelected).getPickName(), x, baseline, mPaint);
    // 繪製上方data
    for (int i = 1; (mCurrentSelected - i) >= 0; i++) {
        drawOtherText(canvas, i, -1);
    }
    // 繪製下方data
    for (int i = 1; (mCurrentSelected + i) < mDataList.size(); i++) {
        drawOtherText(canvas, i, 1);
    }

}
 
開發者ID:woniukeji,項目名稱:jianguo,代碼行數:24,代碼來源:PickerType.java

示例12: drawData

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
private void drawData(Canvas canvas) {
    // 先繪製選中的text再往上往下繪製其餘的text
    float scale = parabola(mViewHeight / 4.0f, mMoveLen);
    float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
    mPaint.setTextSize(size);
    mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
    // text居中繪製,注意baseline的計算才能達到居中,y值是text中心坐標
    float x = (float) (mViewWidth / 2.0);
    float y = (float) (mViewHeight / 2.0 + mMoveLen);
    FontMetricsInt fmi = mPaint.getFontMetricsInt();
    float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));

    canvas.drawText(mDataList.get(mCurrentSelected), x, baseline, mPaint);
    // 繪製上方data
    for (int i = 1; (mCurrentSelected - i) >= 0; i++) {
        drawOtherText(canvas, i, -1);
    }
    // 繪製下方data
    for (int i = 1; (mCurrentSelected + i) < mDataList.size(); i++) {
        drawOtherText(canvas, i, 1);
    }

}
 
開發者ID:woniukeji,項目名稱:jianguo,代碼行數:24,代碼來源:PickerView.java

示例13: drawData

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
private void drawData(Canvas canvas)
{
	// 先繪製選中的text再往上往下繪製其餘的text
	float scale = parabola(mViewHeight / 4.0f, mMoveLen);
	float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
	mPaint.setTextSize(size);
	mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
	// text居中繪製,注意baseline的計算才能達到居中,y值是text中心坐標
	float x = (float) (mViewWidth / 2.0);
	float y = (float) (mViewHeight / 2.0 + mMoveLen);
	FontMetricsInt fmi = mPaint.getFontMetricsInt();
	float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));

	canvas.drawText(mDataList.get(mCurrentSelected), x, baseline, mPaint);
       //暴力法則,上下都最多繪製10條數據
       int count = Math.min(10, mDataList.size());
       // 繪製上方data
       for (int i = 1; i <= count; i++) {
           drawOtherText(canvas, i, -1);
	}
	// 繪製下方data
	for (int i = 1; i <= count; i++) {
           drawOtherText(canvas, i, 1);
	}

}
 
開發者ID:captain-miao,項目名稱:AndroidStartupDemo,代碼行數:27,代碼來源:PickerViewCircle.java

示例14: drawOtherText

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
/**
 * @param canvas
 * @param position
 *            距離mCurrentSelected的差
 * @param type
 *            1表示向下繪製,-1表示向上繪製
 */
private void drawOtherText(Canvas canvas, int position, int type)
{
	float d = (float) (MARGIN_ALPHA * mMinTextSize * position + type
			* mMoveLen);
	float scale = parabola(mViewHeight / 4.0f, d);
	float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
	mPaint.setTextSize(size);
	mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
	float y = (float) (mViewHeight / 2.0 + type * d);
	FontMetricsInt fmi = mPaint.getFontMetricsInt();
	float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));
       int valuePosition = mCurrentSelected + type * position;
       //調整位置偏差在 合法範圍
       int dataSize = mDataList.size();
       valuePosition = (valuePosition + dataSize) % dataSize;
       //if(valuePosition >= 0 & valuePosition < dataSize) {//以防萬一
           canvas.drawText(mDataList.get(valuePosition),
                   (float) (mViewWidth / 2.0), baseline, mPaint);
       //}
}
 
開發者ID:captain-miao,項目名稱:AndroidStartupDemo,代碼行數:28,代碼來源:PickerViewCircle.java

示例15: computeTextProperty

import android.graphics.Paint.FontMetricsInt; //導入依賴的package包/類
private static TextProperty computeTextProperty(final String string,
		final int width, final int height, final Paint paint) {
	final FontMetricsInt fm = paint.getFontMetricsInt();
	final int h = (int) Math.ceil(fm.bottom - fm.top);
	int maxContentWidth = 0;

	final String[] lines = Cocos2dxBitmap.splitString(string, width,
			height, paint);

	if (width != 0) {
		maxContentWidth = width;
	} else {
		/* Compute the max width. */
		int temp = 0;
		for (final String line : lines) {
			temp = (int) FloatMath.ceil(paint.measureText(line, 0,
					line.length()));
			if (temp > maxContentWidth) {
				maxContentWidth = temp;
			}
		}
	}

	return new TextProperty(maxContentWidth, h, lines);
}
 
開發者ID:fansongy,項目名稱:Example-of-Cocos2DX,代碼行數:26,代碼來源:Cocos2dxBitmap.java


注:本文中的android.graphics.Paint.FontMetricsInt類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。