本文整理汇总了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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
//}
}
示例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);
}