本文整理匯總了Java中android.text.Layout.Alignment.ALIGN_NORMAL屬性的典型用法代碼示例。如果您正苦於以下問題:Java Alignment.ALIGN_NORMAL屬性的具體用法?Java Alignment.ALIGN_NORMAL怎麽用?Java Alignment.ALIGN_NORMAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.text.Layout.Alignment
的用法示例。
在下文中一共展示了Alignment.ALIGN_NORMAL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseTextAlignment
private static Alignment parseTextAlignment(String s) {
switch (s) {
case "start":
case "left":
return Alignment.ALIGN_NORMAL;
case "center":
case "middle":
return Alignment.ALIGN_CENTER;
case "end":
case "right":
return Alignment.ALIGN_OPPOSITE;
default:
Log.w(TAG, "Invalid alignment value: " + s);
return null;
}
}
示例2: draw
@Override
public void draw(Canvas canvas) {
canvas.save();
mPaint.setColor(Color.TRANSPARENT);
Rect rect = new Rect(0, 0, mDrawableWidth, mDrawableHeight);
canvas.drawRect(rect, mPaint);
mPaint.setColor(mTextBgColor);
RectF rectf = new RectF(mMarginLeft, mMarginTop, mDrawableWidth
- mMarginRight, mDrawableHeight - mMarginBottom);
canvas.drawRoundRect(rectf, mRoundRectRadiusX, mRoundRectRadiusY,
mPaint);
canvas.translate(mMarginLeft + mPaddingLeft, mMarginTop + mPaddingTop);
canvas.clipRect(0, 0, mContentWidth, mContentHeight);
mPaint.setColor(mTextFgColor);
StaticLayout layout = new StaticLayout(mContent, mPaint, mContentWidth,
Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true);
layout.draw(canvas);
canvas.restore();
}
示例3: measurePlainText
private void measurePlainText(int widthMeasureSpec, int heightMeasureSpec) {
int paddingLeft = this.getPaddingLeft();
int paddingRight = this.getPaddingRight();
int paddingTop = this.getPaddingTop();
int paddingBottom = this.getPaddingBottom();
// max allowed width or height
int sizeWidth = MeasureSpec.getSize(widthMeasureSpec) - paddingLeft - paddingRight;
int sizeHeight = MeasureSpec.getSize(heightMeasureSpec) - paddingTop - paddingBottom;
// mode
int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
// calculate text width and height
mPaint.setTextSize(mTextSize);
mStaticLayout = new StaticLayout(mTextString, mPaint, sizeWidth, Alignment.ALIGN_NORMAL, 1.0f, 0, false);
// measured width and height
int measuredWidth =
modeWidth == MeasureSpec.EXACTLY ? sizeWidth : Math.min(sizeWidth,
(int) Math.ceil(Layout.getDesiredWidth(mTextString, mPaint)));
int measuredHeight = modeHeight == MeasureSpec.EXACTLY ? sizeHeight : mStaticLayout.getHeight();
setMeasuredDimension(measuredWidth + paddingLeft + paddingRight, measuredHeight + paddingTop + paddingBottom);
}
示例4: getIntrinsicHeight
@Override
public int getIntrinsicHeight() {
StaticLayout layout = new StaticLayout(mContent, mPaint, mContentWidth,
Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true);
int textHeight = layout.getHeight();
int height = 0;
if (textHeight + mPaddingTop + mPaddingBottom + mMarginTop
+ mMarginBottom > mMaxHeight) {
height = mMaxHeight;
mContentHeight = height - mPaddingTop - mPaddingBottom - mMarginTop
- mMarginBottom;
} else {
height = textHeight + mPaddingTop + mPaddingBottom + mMarginTop
+ mMarginBottom;
mContentHeight = textHeight;
}
return height;
}
示例5: drawText
private static void drawText(Canvas canvas, int xStart, int yStart,
int xWidth, int yHeigth, String textToDisplay,
TextPaint paintToUse, float startTextSizeInPixels,
float stepSizeForTextSizeSteps) {
// Text view line spacing multiplier
float mSpacingMult = 1.0f;
// Text view additional line spacing
float mSpacingAdd = 0.0f;
StaticLayout l = null;
do {
paintToUse.setTextSize(startTextSizeInPixels);
startTextSizeInPixels -= stepSizeForTextSizeSteps;
l = new StaticLayout(textToDisplay, paintToUse, xWidth,
Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true);
} while (l.getHeight() > yHeigth);
int textCenterX = xStart + (xWidth / 2);
int textCenterY = (yHeigth - l.getHeight()) / 2;
canvas.save();
canvas.translate(textCenterX, textCenterY);
l.draw(canvas);
canvas.restore();
}
示例6: onTestSize
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public int onTestSize(int suggestedSize, RectF availableSPace) {
mPaint.setTextSize(suggestedSize);
String text = getText().toString();
boolean singleline = getMaxLines() == 1;
if (singleline) {
mTextRect.bottom = mPaint.getFontSpacing();
mTextRect.right = mPaint.measureText(text);
} else {
StaticLayout layout = new StaticLayout(text, mPaint,
mWidthLimit, Alignment.ALIGN_NORMAL, mSpacingMult,
mSpacingAdd, true);
// return early if we have more lines
if (getMaxLines() != NO_LINE_LIMIT
&& layout.getLineCount() > getMaxLines()) {
return 1;
}
mTextRect.bottom = layout.getHeight();
int maxWidth = -1;
for (int i = 0; i < layout.getLineCount(); i++) {
if (maxWidth < layout.getLineWidth(i)) {
maxWidth = (int) layout.getLineWidth(i);
}
}
mTextRect.right = maxWidth;
}
mTextRect.offsetTo(0, 0);
if (availableSPace.contains(mTextRect)) {
// may be too small, don't worry we will find the best match
return -1;
} else {
// too big
return 1;
}
}
示例7: getTextHeight
private int getTextHeight(CharSequence source, TextPaint paint, int width, float textSize) {
// modified: make a copy of the original TextPaint object for measuring
// (apparently the object gets modified while measuring, see also the
// docs for TextView.getPaint() (which states to access it read-only)
TextPaint paintCopy = new TextPaint(paint);
// Update the text paint object
paintCopy.setTextSize(textSize);
// Measure using a static layout
StaticLayout layout = new StaticLayout(source, paintCopy, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true);
return layout.getHeight();
}
示例8: draw
@Override public void draw(@NonNull Canvas canvas) {
Paint paint = new Paint();
paint.setColor(textColor);
paint.setStyle(Style.STROKE);
int numberOfColumns = tableRow.size();
if (numberOfColumns == 0) {
return;
}
int columnWidth = tableWidth / numberOfColumns;
int offset;
for (int i = 0; i < numberOfColumns; i++) {
offset = i * columnWidth;
if (paintBorder) {
// The rect is open at the bottom, so there's a single line
// between rows.
canvas.drawRect(offset, 0, offset + columnWidth, rowHeight, paint);
}
StaticLayout layout = new StaticLayout(tableRow.get(i),
getTextPaint(), (columnWidth - 2 * PADDING),
Alignment.ALIGN_NORMAL, 1.5f, 0.5f, true);
canvas.translate(offset + PADDING, 0);
layout.draw(canvas);
canvas.translate(-1 * (offset + PADDING), 0);
}
}
示例9: onMeasure
@SuppressLint({"DrawAllocation"})
protected void onMeasure(int i, int i2) {
try {
super.onMeasure(i, i2);
} catch (Throwable e) {
FirebaseCrash.report(e);
setMeasuredDimension(MeasureSpec.getSize(i), AndroidUtilities.dp(51.0f));
FileLog.e("tmessages", e);
}
this.f399b = null;
if (this.f398a != null && this.f398a.length() > 0) {
CharSequence text = getText();
if (text.length() > 1 && text.charAt(0) == '@') {
int indexOf = TextUtils.indexOf(text, ' ');
if (indexOf != -1) {
TextPaint paint = getPaint();
int ceil = (int) Math.ceil((double) paint.measureText(text, 0, indexOf + 1));
int measuredWidth = (getMeasuredWidth() - getPaddingLeft()) - getPaddingRight();
this.f400c = text.subSequence(0, indexOf + 1).length();
CharSequence ellipsize = TextUtils.ellipsize(this.f398a, paint, (float) (measuredWidth - ceil), TruncateAt.END);
this.f401d = ceil;
try {
this.f399b = new StaticLayout(ellipsize, getPaint(), measuredWidth - ceil, Alignment.ALIGN_NORMAL, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT, 0.0f, false);
if (this.f399b.getLineCount() > 0) {
this.f401d = (int) (((float) this.f401d) + (-this.f399b.getLineLeft(0)));
}
this.f402e = ((getMeasuredHeight() - this.f399b.getLineBottom(0)) / 2) + AndroidUtilities.dp(0.5f);
} catch (Throwable e2) {
FirebaseCrash.report(e2);
FileLog.e("tmessages", e2);
}
}
}
}
}
示例10: makeLayout
private Layout makeLayout(CharSequence text) {
CharSequence transformed;
if (this.mSwitchTransformationMethod != null) {
transformed = this.mSwitchTransformationMethod.getTransformation(text, this);
} else {
transformed = text;
}
return new StaticLayout(transformed, this.mTextPaint, transformed != null ? (int) Math.ceil((double) Layout.getDesiredWidth(transformed, this.mTextPaint)) : 0, Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
}
示例11: fitsParent
private static boolean fitsParent(final String text, final TextPaint paint, final float parentW, final float parentH, float textSize) {
paint.setTextSize(textSize);
Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
StaticLayout textLayout = new StaticLayout(text, paint, bounds.width(), Alignment.ALIGN_NORMAL, 0.0f, 0.0f, false);
return (textLayout.getHeight() <= parentH && textLayout.getWidth() <= parentW) &&
(Math.abs(parentH - textLayout.getHeight()) >= 0 &&
Math.abs(parentW - textLayout.getWidth()) >= 0);
}
示例12: getTextHeight
private int getTextHeight(CharSequence source, TextPaint paint, int width, float textSize) {
// modified: make a copy of the original TextPaint object for measuring
// (apparently the object gets modified while measuring, see also the
// docs for TextView.getPaint() (which states to access it read-only)
TextPaint paintCopy = new TextPaint(paint);
// Update the text paint object
paintCopy.setTextSize(textSize );
// Measure using a static layout
StaticLayout layout = new StaticLayout(source, paintCopy, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true);
return layout.getHeight();
}
示例13: getTextLineCount
private int getTextLineCount(CharSequence source, TextPaint paint, int widthPx, float textSize) {
paint.setTextSize(textSize);
StaticLayout layout = new StaticLayout(source, paint, widthPx, Alignment.ALIGN_NORMAL,
mSpacingMult,
mSpacingAdd, true);
layout.draw(TEXT_RESIZE_CANVAS);
return layout.getLineCount();
}
示例14: getTextHeight
private int getTextHeight(CharSequence source, TextPaint paint, int width, float textSize) {
// Update the text paint object
paint.setTextSize(textSize);
// Draw using a static layout
StaticLayout layout = new StaticLayout(source, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, false);
layout.draw(sTextResizeCanvas);
return layout.getHeight();
}
示例15: onTestSize
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public int onTestSize(int suggestedSize, RectF availableSPace) {
mPaint.setTextSize(suggestedSize);
String text = getText().toString();
boolean singleline = getMaxLines() == 1;
if (singleline) {
mTextRect.bottom = mPaint.getFontSpacing();
mTextRect.right = mPaint.measureText(text);
} else {
StaticLayout layout = new StaticLayout(text, mPaint,
mWidthLimit, Alignment.ALIGN_NORMAL, mSpacingMult,
mSpacingAdd, true);
// return early if we have more lines
if (getMaxLines() != NO_LINE_LIMIT
&& layout.getLineCount() > getMaxLines()) {
return 1;
}
mTextRect.bottom = layout.getHeight();
int maxWidth = -1;
for (int i = 0; i < layout.getLineCount(); i++) {
if (maxWidth < layout.getLineWidth(i)) {
maxWidth = (int) layout.getLineWidth(i);
}
}
mTextRect.right = maxWidth;
}
mTextRect.offsetTo(0, 0);
if (availableSPace.contains(mTextRect)) {
// may be too small, don't worry we will find the best match
return -1;
} else {
// too big
return 1;
}
}