本文整理汇总了Java中android.graphics.Paint.FontMetricsInt方法的典型用法代码示例。如果您正苦于以下问题:Java Paint.FontMetricsInt方法的具体用法?Java Paint.FontMetricsInt怎么用?Java Paint.FontMetricsInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Paint
的用法示例。
在下文中一共展示了Paint.FontMetricsInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: chooseHeight
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void chooseHeight(final CharSequence text, final int start, final int end, final int spanstartv, final int v, final Paint.FontMetricsInt fm) {
int need = height - (v + fm.descent - fm.ascent - spanstartv);
if (need > 0) {
if (mVerticalAlignment == ALIGN_TOP) {
fm.descent += need;
} else if (mVerticalAlignment == ALIGN_CENTER) {
fm.descent += need / 2;
fm.ascent -= need / 2;
} else {
fm.ascent -= need;
}
}
need = height - (v + fm.bottom - fm.top - spanstartv);
if (need > 0) {
if (mVerticalAlignment == ALIGN_TOP) {
fm.top += need;
} else if (mVerticalAlignment == ALIGN_CENTER) {
fm.bottom += need / 2;
fm.top -= need / 2;
} else {
fm.top -= need;
}
}
}
示例2: drawTopLeftTip
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* 左上角画梯形
* @param canvas
* @param realWaist 腰长
*/
private void drawTopLeftTip(Canvas canvas, float realWaist) {
path.moveTo(this.realStartDisH, 0);
path.lineTo(this.realStartDisH + realWaist, 0);
path.lineTo(0, this.realStartDisH + realWaist);
path.lineTo(0, this.realStartDisH);
path.close();
canvas.drawPath(path, backPaint);
canvas.save();
Paint.FontMetricsInt fontMetrics = textPaint.getFontMetricsInt();
float dis = (waistDis /2 + this.startDisH) /2;
float disY = dis - (fontMetrics.bottom + fontMetrics.top) / 2f;
canvas.rotate(-45, dis, dis);
canvas.drawText(tipContent, dis, disY, textPaint);
canvas.rotate(45, dis, dis);
canvas.restore();
}
示例3: onDraw
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas canvas) {
// paint.setColor(Color.WHITE);
// paint.setAlpha(0xff);
// canvas.drawRect(0,0,SIZE,SIZE,paint);
paint.setColor(Color.BLACK);
paint.setAlpha(0x33);
canvas.drawCircle(SIZE / 2, SIZE / 2, SIZE / 2, paint);
paint.setColor(Color.WHITE);
paint.setAlpha(0xff);
Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt();
int baseline = (SIZE - fontMetrics.bottom - fontMetrics.top) / 2;
canvas.drawText(count, SIZE / 2, baseline, paint);
}
示例4: getSize
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
// return super.getSize(paint, text, start, end, fm);
// fm 以 Paint 的 fm 为基准,避免 Span 改变了 fm 导致文字行高变化 -- chant
Drawable d = getCachedDrawable();
Rect rect = d.getBounds();
if (fm != null) {
Paint.FontMetricsInt pfm = paint.getFontMetricsInt();
// keep it the same as paint's fm
fm.ascent = pfm.ascent;
fm.descent = pfm.descent;
fm.top = pfm.top;
fm.bottom = pfm.bottom;
}
return rect.right;
}
示例5: getSize
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
if (fm == null) {
fm = new Paint.FontMetricsInt();
}
int sz = super.getSize(paint, text, start, end, fm);
int offset = AndroidUtilities.dp(6);
int w = (fm.bottom - fm.top) / 2;
fm.top = -w - offset;
fm.bottom = w - offset;
fm.ascent = -w - offset;
fm.leading = 0;
fm.descent = w - offset;
return sz;
}
示例6: getSize
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
Drawable d = getCachedDrawable();
Rect rect = d.getBounds();
if (fm != null) {
// Centers the text with the ImageSpan
if (rect.bottom - (fm.descent - fm.ascent) >= 0){
// Stores the initial descent and computes the margin available
initialDescent = fm.descent;
extraSpace = rect.bottom - (fm.descent - fm.ascent);
}
fm.descent = extraSpace / 2 + initialDescent;
fm.bottom = fm.descent;
fm.ascent = -rect.bottom + fm.descent;
fm.top = fm.ascent;
}
return rect.right;
}
示例7: getSize
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
CharSequence categoryName = getCategoryName(text, start, end);
if (categoryName == null) {
return 0;
}
float density = context.getResources().getDisplayMetrics().density;
int iconBackgroundSize = (int) (ICON_BACKGROUND_SIZE * density);
int textLeadingPadding = (int) (TEXT_LEADING_PADDING * density);
int textWidth = (int) paint.measureText(categoryName.toString());
int textTrailingPadding = (int) (TEXT_TRAILING_PADDING * density);
int whiteSpacePadding = (int) (WHITE_SPACE_PADDING_AT_END * density);
return iconBackgroundSize + textLeadingPadding + textWidth + textTrailingPadding + whiteSpacePadding;
}
示例8: 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;
}
示例9: getSize
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(@NonNull Paint paint, CharSequence text,
int start, int end, Paint.FontMetricsInt fm) {
if (fm != null) {
paint.getFontMetricsInt(fm);
}
int textWidth = (int) Math.ceil(paint.measureText(text, start, end));
return Math.min(textWidth, mClipRect.width());
}
示例10: chooseHeight
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int v, Paint.FontMetricsInt fm) {
if(WXEnvironment.isApkDebugable()) {
WXLogUtils.d("LineHeight", text + " ; start " + start + "; end " + end + "; spanstartv "
+ spanstartv + "; v " + v + "; fm " + fm);
}
int halfLeading=(lineHeight-(fm.descent-fm.ascent))/2;
fm.top-=halfLeading;
fm.bottom+=halfLeading;
fm.ascent-=halfLeading;
fm.descent+=halfLeading;
}
示例11: getSize
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
if (fm != null) {
fm.ascent = -Math.round(mHeight);
fm.descent = 0;
fm.top = fm.ascent;
fm.bottom = 0;
}
return Math.round(mWidth);
}
示例12: drawRect
import android.graphics.Paint; //导入方法依赖的package包/类
private void drawRect(Canvas canvas) {
canvas.drawRect(mBgRect, mBackgroundPaint);
mProgressRect.set(getPaddingLeft(), getPaddingTop(), getPaddingLeft() + parseValueToWidth(), getPaddingTop() + mHeight);
canvas.drawRect(mProgressRect, mPaint);
if (mText != null && mText.length() > 0) {
Paint.FontMetricsInt fontMetrics = mTextPaint.getFontMetricsInt();
float baseline = mBgRect.top + (mBgRect.height() - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
canvas.drawText(mText, mBgRect.centerX(), baseline, mTextPaint);
}
}
示例13: onCreateView
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_trakt_login, container, false);
mErrorFrame = (ViewGroup) root.findViewById(android.support.v17.leanback.R.id.error_frame);
updateBackground();
// installTitleView(inflater, mErrorFrame, savedInstanceState);
mImageView = (ImageView) root.findViewById(android.support.v17.leanback.R.id.image);
setImageDrawable((getActivity().getResources().getDrawable(R.drawable.logo_trakt)));
updateImageDrawable();
mTextView = (TextView) root.findViewById(android.support.v17.leanback.R.id.message);
updateMessage();
mButton = (Button) root.findViewById(android.support.v17.leanback.R.id.button);
updateButton();
mSiteText = (TextView) root.findViewById(R.id.text_url);
mCodeText = (TextView) root.findViewById(R.id.text_code);
Paint.FontMetricsInt metrics = getFontMetricsInt(mTextView);
int underImageBaselineMargin = container.getResources().getDimensionPixelSize(
android.support.v17.leanback.R.dimen.lb_error_under_image_baseline_margin);
setTopMargin(mTextView, underImageBaselineMargin + metrics.ascent);
int underMessageBaselineMargin = container.getResources().getDimensionPixelSize(
android.support.v17.leanback.R.dimen.lb_error_under_message_baseline_margin);
setTopMargin(mButton, underMessageBaselineMargin - metrics.descent);
return root;
}
示例14: getSize
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
if (fm == null) {
fm = new Paint.FontMetricsInt();
}
if (fontMetrics == null) {
int sz = super.getSize(paint, text, start, end, fm);
int offset = AndroidUtilities.dp(8);
int w = AndroidUtilities.dp(10);
fm.top = -w - offset;
fm.bottom = w - offset;
fm.ascent = -w - offset;
fm.leading = 0;
fm.descent = w - offset;
return sz;
} else {
if (fm != null) {
fm.ascent = fontMetrics.ascent;
fm.descent = fontMetrics.descent;
fm.top = fontMetrics.top;
fm.bottom = fontMetrics.bottom;
}
if (getDrawable() != null) {
getDrawable().setBounds(0, 0, size, size);
}
return size;
}
}
示例15: EmojiSpan
import android.graphics.Paint; //导入方法依赖的package包/类
public EmojiSpan(EmojiDrawable d, int verticalAlignment, int s, Paint.FontMetricsInt original) {
super(d, verticalAlignment);
fontMetrics = original;
if (original != null) {
size = Math.abs(fontMetrics.descent) + Math.abs(fontMetrics.ascent);
if (size == 0) {
size = AndroidUtilities.dp(20);
}
}
}