本文整理汇总了Java中android.text.StaticLayout.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java StaticLayout.getWidth方法的具体用法?Java StaticLayout.getWidth怎么用?Java StaticLayout.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.StaticLayout
的用法示例。
在下文中一共展示了StaticLayout.getWidth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: measure
import android.text.StaticLayout; //导入方法依赖的package包/类
private void measure() {
TextPaint tp = new TextPaint();
tp.setAntiAlias(true);
tp.setColor(mTextColor);
tp.setTextSize(mTextSize);
strokePaint.setTextSize(mTextSize);
// tp.setShadowLayer(4, 0, 0, Color.BLACK);
mContentHeight = getFontHeight(tp);
staticLayout = new StaticLayout(mContent,
tp,
(int) Layout.getDesiredWidth(mContent, 0, mContent.length(), tp) + 1,
Layout.Alignment.ALIGN_NORMAL,
1.0f,
0.0f,
false);
mContentWidth = staticLayout.getWidth();
borderStaticLayout = new StaticLayout(mContent,
strokePaint,
(int) Layout.getDesiredWidth(mContent, 0, mContent.length(), tp) + 1,
Layout.Alignment.ALIGN_NORMAL,
1.0f,
0.0f,
false);
}
示例2: getDx
import android.text.StaticLayout; //导入方法依赖的package包/类
private float getDx(final int width,
final int horizontalGravity,
final Paint paint,
final StaticLayout layout) {
final boolean centered = paint.getTextAlign() == Paint.Align.CENTER;
final float dx;
switch (horizontalGravity) { // No support for GravityCompat.END
case Gravity.CENTER_HORIZONTAL:
dx = (width >> 1) - (centered ? 0 : (layout.getWidth() >> 1) - getPaddingLeft());
break;
default:
case GravityCompat.START:
dx = getPaddingLeft();
break;
}
return dx;
}
示例3: getOverlayBitmap2
import android.text.StaticLayout; //导入方法依赖的package包/类
public static Bitmap getOverlayBitmap2(Context context, Bitmap bitmap, String text) {
Bitmap result = bitmap.copy(bitmap.getConfig(), true);
float scale = context.getResources().getDisplayMetrics().density;
Canvas canvas = new Canvas(result);
TextPaint mTextPaint = new TextPaint();
mTextPaint.setTextSize((int) (12 * scale));
mTextPaint.setColor(Color.WHITE);
mTextPaint.setAlpha(204);
mTextPaint.setShadowLayer(5f, 0f, 1f, Color.DKGRAY);
StaticLayout mTextLayout = new StaticLayout(text, mTextPaint, canvas.getWidth() - Util.dpToPx(87), Layout.Alignment.ALIGN_CENTER, 1.0f, 0.3f, true);
canvas.save();
float textX = (canvas.getWidth() / 2) - (mTextLayout.getWidth() / 2);
float textY = result.getHeight() - Util.dpToPx(72);
canvas.translate(textX, textY);
mTextLayout.draw(canvas);
canvas.restore();
return result;
}
示例4: addText
import android.text.StaticLayout; //导入方法依赖的package包/类
private void addText() {
mTextPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTextSize, getResources().getDisplayMetrics()));
if (!"roboto.ttf".equals(mTypeface)) {
mTextPaint.setTypeface(Typeface.createFromAsset(mContext.getAssets(), mTypeface));
mTextStrokePaint.setTypeface(Typeface.createFromAsset(mContext.getAssets(), mTypeface));
}
mTextPaint.setFakeBoldText(true);
mTextPaint.setAntiAlias(true);
mTextPaint.setShadowLayer(mShadowRadius, mShadowDisX, mShadowDisY, mShadowColor);
mTextStrokePaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTextSize, getResources().getDisplayMetrics()));
mTextStrokePaint.setStrokeWidth(mStrokeWidth);
mTextStrokePaint.setStyle(Paint.Style.STROKE);
mTextStrokePaint.setFakeBoldText(true);
mTextStrokePaint.setAntiAlias(true);
if (mTextGravity == WidgetTextBean.GRAVITY_CENTER || mTextGravity == WidgetTextBean.GRAVITY_HORIZONTAL_CENTER) {
mAlignment = StaticLayout.Alignment.ALIGN_CENTER;
} else {
mAlignment = StaticLayout.Alignment.ALIGN_NORMAL;
}
mLayout = new StaticLayout(applyLetterSpacing(mText), mTextPaint, mTextRect.width(), mAlignment, 0.9f, mLineSpace, false);
mStrokeLayout = new StaticLayout(applyLetterSpacing(mText), mTextStrokePaint, mTextRect.width(), mAlignment, 0.9f, mLineSpace, false);
// mTextWidth = mTextPaint.measureText(mText);;
mTextWidth = mLayout.getWidth();
mTextHeight = mStrokeLayout.getHeight() >= mLayout.getHeight() ? mStrokeLayout.getHeight() : mLayout.getHeight();
initColor();
}
示例5: drawMultilineText
import android.text.StaticLayout; //导入方法依赖的package包/类
public static void drawMultilineText(Canvas c, StaticLayout textLayout,
float x, float y,
TextPaint paint,
MPPointF anchor, float angleDegrees) {
float drawOffsetX = 0.f;
float drawOffsetY = 0.f;
float drawWidth;
float drawHeight;
final float lineHeight = paint.getFontMetrics(mFontMetricsBuffer);
drawWidth = textLayout.getWidth();
drawHeight = textLayout.getLineCount() * lineHeight;
// Android sometimes has pre-padding
drawOffsetX -= mDrawTextRectBuffer.left;
// Android does not snap the bounds to line boundaries,
// and draws from bottom to top.
// And we want to normalize it.
drawOffsetY += drawHeight;
// To have a consistent point of reference, we always draw left-aligned
Paint.Align originalTextAlign = paint.getTextAlign();
paint.setTextAlign(Paint.Align.LEFT);
if (angleDegrees != 0.f) {
// Move the text drawing rect in a way that it always rotates around its center
drawOffsetX -= drawWidth * 0.5f;
drawOffsetY -= drawHeight * 0.5f;
float translateX = x;
float translateY = y;
// Move the "outer" rect relative to the anchor, assuming its centered
if (anchor.x != 0.5f || anchor.y != 0.5f) {
final FSize rotatedSize = getSizeOfRotatedRectangleByDegrees(
drawWidth,
drawHeight,
angleDegrees);
translateX -= rotatedSize.width * (anchor.x - 0.5f);
translateY -= rotatedSize.height * (anchor.y - 0.5f);
FSize.recycleInstance(rotatedSize);
}
c.save();
c.translate(translateX, translateY);
c.rotate(angleDegrees);
c.translate(drawOffsetX, drawOffsetY);
textLayout.draw(c);
c.restore();
} else {
if (anchor.x != 0.f || anchor.y != 0.f) {
drawOffsetX -= drawWidth * anchor.x;
drawOffsetY -= drawHeight * anchor.y;
}
drawOffsetX += x;
drawOffsetY += y;
c.save();
c.translate(drawOffsetX, drawOffsetY);
textLayout.draw(c);
c.restore();
}
paint.setTextAlign(originalTextAlign);
}