本文整理汇总了Java中android.text.Layout.Alignment.ALIGN_CENTER属性的典型用法代码示例。如果您正苦于以下问题:Java Alignment.ALIGN_CENTER属性的具体用法?Java Alignment.ALIGN_CENTER怎么用?Java Alignment.ALIGN_CENTER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.text.Layout.Alignment
的用法示例。
在下文中一共展示了Alignment.ALIGN_CENTER属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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_CENTER,
mSpacingMult, mSpacingAdd, true );
layout.draw ( sTextResizeCanvas );
return layout.getHeight ();
}
示例3: setCustomEmptyText
public void setCustomEmptyText(CharSequence text) {
if (text == null) {
emptyLayout = null;
} else {
UI.textPaint.setTextSize(UI._22sp);
emptyLayout = new StaticLayout(text, UI.textPaint, (viewWidth < (UI.controlLargeMargin << 1)) ? 0 : (viewWidth - (UI.controlLargeMargin << 1)), Alignment.ALIGN_CENTER, 1, 0, false);
}
}
示例4: setCustomEmptyText
public void setCustomEmptyText(CharSequence text) {
if (text == null) {
emptyLayout = null;
} else {
UI.textPaint.setTextSize(UI._22sp);
final int w = getWidth();
emptyLayout = new StaticLayout(text, UI.textPaint, (w < (UI._16dp << 1)) ? 0 : (w - (UI._16dp << 1)), Alignment.ALIGN_CENTER, 1, 0, false);
}
}
示例5: createTextBitmap
/** You own the bitmap after this and you must call recycle on it. */
Bitmap createTextBitmap(String text) {
Bitmap b = Bitmap.createBitmap(mBitmapWidth, mBitmapHeight,
Bitmap.Config.ALPHA_8);
b.setDensity(mDensity);
Canvas c = new Canvas(b);
StaticLayout layout = new StaticLayout(text, mTextPaint,
(int) mTextWidth, Alignment.ALIGN_CENTER, 1, 0, true);
int lineCount = layout.getLineCount();
if (lineCount > MAX_LINES) {
lineCount = MAX_LINES;
}
// if (!TEXT_BURN && lineCount > 0) {
// RectF bubbleRect = mBubbleRect;
// bubbleRect.bottom = height(lineCount);
// c.drawRoundRect(bubbleRect, mCornerRadius, mCornerRadius,
// mRectPaint);
// }
for (int i = 0; i < lineCount; i++) {
// int x = (int)((mBubbleRect.width() - layout.getLineMax(i)) /
// 2.0f);
// int y = mFirstLineY + (i * mLineHeight);
final String lineText = text.substring(layout.getLineStart(i),
layout.getLineEnd(i));
int x = (int) (mBubbleRect.left + ((mBubbleRect.width() - mTextPaint
.measureText(lineText)) * 0.5f));
int y = mFirstLineY + (i * mLineHeight);
c.drawText(lineText, x, y, mTextPaint);
}
return b;
}
示例6: setCustomEmptyText
public void setCustomEmptyText(CharSequence text) {
if (text == null) {
emptyLayout = null;
} else {
UI.textPaint.setTextSize(UI._Headingsp);
emptyLayout = new StaticLayout(text, UI.textPaint, (viewWidth < (UI.controlLargeMargin << 1)) ? 0 : (viewWidth - (UI.controlLargeMargin << 1)), Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
}
}
示例7: CanvasTextArea
public CanvasTextArea(CanvasHost canvasHost, LayoutAttrSet layoutAttrSet) {
super(canvasHost, layoutAttrSet);
this.mPaint.density = canvasHost.getContext().getResources().getDisplayMetrics().density;
if (layoutAttrSet != null) {
if (layoutAttrSet.getAttr(TextColor, null) != null) {
String attr = layoutAttrSet.getAttr(TextColor, null);
if (!TextUtils.isEmpty(attr)) {
try {
setTextColor(Color.parseColor(attr));
} catch (Exception e) {
}
}
}
if (layoutAttrSet.hasAttr(TextSize)) {
setTextSize((float) layoutAttrSet.getAttr(TextSize, 15));
}
if (layoutAttrSet.hasAttr(MaxLine)) {
setMaxLines(layoutAttrSet.getAttr(MaxLine, Integer.MAX_VALUE));
}
if (layoutAttrSet.getAttr("text", null) != null) {
CharSequence attr2 = layoutAttrSet.getAttr("text", null);
if (!TextUtils.isEmpty(attr2)) {
setText(attr2);
}
}
String str = "ALIGN_NORMAL";
if (layoutAttrSet.hasAttr(TextAlignment)) {
str = layoutAttrSet.getAttr(TextAlignment, "ALIGN_NORMAL");
}
boolean z = true;
switch (str.hashCode()) {
case -1371700497:
if (str.equals("ALIGN_CENTER")) {
z = true;
this.mLayoutAlignment = Alignment.ALIGN_CENTER;
break;
}
break;
case -1047432319:
if (str.equals("ALIGN_NORMAL")) {
z = false;
this.mLayoutAlignment = Alignment.ALIGN_NORMAL;
break;
}
break;
case 1015327489:
if (str.equals("ALIGN_OPPOSITE")) {
z = true;
this.mLayoutAlignment = Alignment.ALIGN_OPPOSITE;
break;
}
break;
default:
throw new RuntimeException("Text alignment\"" + str + "\" is not supported");
}
}
setEllipsize(TextUtils.TruncateAt.END);
}
示例8: getAlignment
@Override
public Alignment getAlignment() {
return Alignment.ALIGN_CENTER;
}
示例9: build
public Cea708Cue build() {
if (isEmpty()) {
// The cue is empty.
return null;
}
SpannableStringBuilder cueString = new SpannableStringBuilder();
// Add any rolled up captions, separated by new lines.
for (int i = 0; i < rolledUpCaptions.size(); i++) {
cueString.append(rolledUpCaptions.get(i));
cueString.append('\n');
}
// Add the current line.
cueString.append(buildSpannableString());
// TODO: Add support for right-to-left languages (i.e. where right would correspond to normal
// alignment).
Alignment alignment;
switch (justification) {
case JUSTIFICATION_FULL:
// TODO: Add support for full justification.
case JUSTIFICATION_LEFT:
alignment = Alignment.ALIGN_NORMAL;
break;
case JUSTIFICATION_RIGHT:
alignment = Alignment.ALIGN_OPPOSITE;
break;
case JUSTIFICATION_CENTER:
alignment = Alignment.ALIGN_CENTER;
break;
default:
throw new IllegalArgumentException("Unexpected justification value: " + justification);
}
float position;
float line;
if (relativePositioning) {
position = (float) horizontalAnchor / RELATIVE_CUE_SIZE;
line = (float) verticalAnchor / RELATIVE_CUE_SIZE;
} else {
position = (float) horizontalAnchor / HORIZONTAL_SIZE;
line = (float) verticalAnchor / VERTICAL_SIZE;
}
// Apply screen-edge padding to the line and position.
position = (position * 0.9f) + 0.05f;
line = (line * 0.9f) + 0.05f;
// anchorId specifies where the anchor should be placed on the caption cue/window. The 9
// possible configurations are as follows:
// 0-----1-----2
// | |
// 3 4 5
// | |
// 6-----7-----8
@AnchorType int verticalAnchorType;
if (anchorId % 3 == 0) {
verticalAnchorType = Cue.ANCHOR_TYPE_START;
} else if (anchorId % 3 == 1) {
verticalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
} else {
verticalAnchorType = Cue.ANCHOR_TYPE_END;
}
// TODO: Add support for right-to-left languages (i.e. where start is on the right).
@AnchorType int horizontalAnchorType;
if (anchorId / 3 == 0) {
horizontalAnchorType = Cue.ANCHOR_TYPE_START;
} else if (anchorId / 3 == 1) {
horizontalAnchorType = Cue.ANCHOR_TYPE_MIDDLE;
} else {
horizontalAnchorType = Cue.ANCHOR_TYPE_END;
}
boolean windowColorSet = (windowFillColor != COLOR_SOLID_BLACK);
return new Cea708Cue(cueString, alignment, line, Cue.LINE_TYPE_FRACTION, verticalAnchorType,
position, horizontalAnchorType, Cue.DIMEN_UNSET, windowColorSet, windowFillColor,
priority);
}
示例10: redraw
private void redraw() {
LogUtils.d(this, "redraw");
SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try {
c = holder.lockCanvas();
if (c != null) {
int width = c.getWidth();
int height = c.getHeight();
int soundWaveHeight = height / 3;
Rect soundwaveBoundingRect = new Rect(0, soundWaveHeight, width, soundWaveHeight * 2);
Rect titleBoundingRect = new Rect(dipToPixels(8),
soundwaveBoundingRect.bottom + dipToPixels(8),
width - dipToPixels(8),
soundwaveBoundingRect.bottom + soundWaveHeight / 2);
c.drawColor(getApplicationContext().getResources().getColor(R.color.black));
c.save();
// draw the inside of the sound wave
int sc = c.saveLayer(0, 0, width, height, null,
Canvas.MATRIX_SAVE_FLAG |
Canvas.CLIP_SAVE_FLAG |
Canvas.HAS_ALPHA_LAYER_SAVE_FLAG |
Canvas.FULL_COLOR_LAYER_SAVE_FLAG |
Canvas.CLIP_TO_LAYER_SAVE_FLAG);
c.clipRect(soundwaveBoundingRect);
Paint paint = new Paint();
paint.setFilterBitmap(false);
paint.setColor(getApplicationContext().getResources().getColor(R.color.orange));
c.drawPaint(paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
c.drawBitmap(mCurrentSoundwave,
new Rect(0,0,mCurrentSoundwave.getWidth(), mCurrentSoundwave.getHeight()),
soundwaveBoundingRect, paint);
paint.setXfermode(null);
c.restore();
c.restoreToCount(sc);
// Draw the title
int startTextSizeInPixels = dipToPixels(16);
TextPaint textPaint = new TextPaint();
textPaint.setTextSize(startTextSizeInPixels);
textPaint.setColor(Color.WHITE);
textPaint.setAntiAlias(true);
// setup the bounding box for the text
int maxRowsCount = (int)Math.floor(((double)titleBoundingRect.height()) / (1.5d * (double)startTextSizeInPixels));
int maxTitleWidth = maxRowsCount * titleBoundingRect.width();
float wholeWidth = textPaint.measureText(mTitle);
StaticLayout sl;
if(wholeWidth > maxTitleWidth) {
int symbolsCount = (int)(maxTitleWidth / (wholeWidth / mTitle.length())) - 4;
String truncated = mTitle.substring(0, symbolsCount) + "...";
sl = new StaticLayout(truncated, 0, truncated.length(),
textPaint, titleBoundingRect.width(),
Alignment.ALIGN_CENTER, 1.0f, 1.0f,
false, null, 0);
}
else {
sl = new StaticLayout(mTitle, 0, mTitle.length(),
textPaint, titleBoundingRect.width(),
Alignment.ALIGN_CENTER, 1.0f, 1.0f,
false, null, 0);
}
// draw the text
c.save();
c.translate(titleBoundingRect.left, titleBoundingRect.top);
sl.draw(c);
c.restore();
}
} finally {
if (c != null)
holder.unlockCanvasAndPost(c);
}
}