本文整理汇总了Java中android.text.Layout.Alignment方法的典型用法代码示例。如果您正苦于以下问题:Java Layout.Alignment方法的具体用法?Java Layout.Alignment怎么用?Java Layout.Alignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Layout
的用法示例。
在下文中一共展示了Layout.Alignment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAlignment
import android.text.Layout; //导入方法依赖的package包/类
public Layout.Alignment getAlignment() {
boolean isRtl = getLayoutDirection() == YogaDirection.RTL;
switch (mAlignment) {
// Layout.Alignment.RIGHT and Layout.Alignment.LEFT are @hide :(
case Gravity.LEFT:
int index = isRtl ? ALIGNMENT_RIGHT : ALIGNMENT_LEFT;
return Layout.Alignment.values()[index];
case Gravity.RIGHT:
index = isRtl ? ALIGNMENT_LEFT : ALIGNMENT_RIGHT;
return Layout.Alignment.values()[index];
case Gravity.CENTER:
return Layout.Alignment.ALIGN_CENTER;
case Gravity.NO_GRAVITY:
default:
return Layout.Alignment.ALIGN_NORMAL;
}
}
示例2: adjustBottomLines
import android.text.Layout; //导入方法依赖的package包/类
/**
* @return True, if adjustments were made that require the view to be invalidated.
*/
private boolean adjustBottomLines() {
// Bail out if we have a zero width; lines will be adjusted during next layout.
if (getWidth() == 0) {
return false;
}
int destBottomLines;
textPaint.setTextSize(bottomTextSize);
if (tempErrorText != null || helperText != null) {
Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ?
Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ?
Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER;
textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true);
destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines);
} else {
destBottomLines = minBottomLines;
}
if (bottomLines != destBottomLines) {
getBottomLinesAnimator(destBottomLines).start();
}
bottomLines = destBottomLines;
return true;
}
示例3: drawIndicatorsTextAbove
import android.text.Layout; //导入方法依赖的package包/类
private void drawIndicatorsTextAbove(Canvas canvas, String text, TextPaint paintText, float x, float y, Layout.Alignment alignment) {
final float textHeight = calculateTextMultilineHeight(text, paintText);
y -= textHeight;
final int width = (int) paintText.measureText(text);
if (x >= getWidth() - settings.paddingCorners) {
x = (getWidth() - width - settings.paddingCorners / 2f);
} else if (x <= 0) {
x = width / 2f;
} else {
x = (x - width / 2f);
}
if (x < 0) {
x = 0;
}
if (x + width > getWidth()) {
x = getWidth() - width;
}
drawText(canvas, text, x, y, paintText, alignment);
}
示例4: adjustBottomLines
import android.text.Layout; //导入方法依赖的package包/类
/**
* @return True, if adjustments were made that require the view to be invalidated.
*/
private boolean adjustBottomLines() {
// Bail out if we have a zero width; lines will be adjusted during next layout.
if (getWidth() == 0) {
return false;
}
int destBottomLines;
textPaint.setTextSize(bottomTextSize);
if (tempErrorText != null || helperText != null) {
Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ?
Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ?
Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER;
textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true);
destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines);
} else {
destBottomLines = minBottomLines;
}
if (bottomLines != destBottomLines) {
getBottomLinesAnimator(destBottomLines).start();
}
bottomLines = destBottomLines;
return true;
}
示例5: getAlignmentByGravity
import android.text.Layout; //导入方法依赖的package包/类
private static Layout.Alignment getAlignmentByGravity(int gravity) {
switch (gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
case Gravity.START:
return Layout.Alignment.ALIGN_NORMAL;
case Gravity.END:
return Layout.Alignment.ALIGN_OPPOSITE;
case Gravity.LEFT:
return Layout.Alignment.ALIGN_LEFT;
case Gravity.RIGHT:
return Layout.Alignment.ALIGN_RIGHT;
case Gravity.CENTER_HORIZONTAL:
return Layout.Alignment.ALIGN_CENTER;
default:
return Layout.Alignment.ALIGN_NORMAL;
}
}
示例6: getTextStyles
import android.text.Layout; //导入方法依赖的package包/类
private static String getTextStyles(Spanned text, int start, int end,
boolean forceNoVerticalMargin, boolean includeTextAlign) {
String margin = null;
String textAlign = null;
if (forceNoVerticalMargin) {
margin = "margin-top:0; margin-bottom:0;";
}
if (includeTextAlign) {
final AlignmentSpan[] alignmentSpans = text.getSpans(start, end, AlignmentSpan.class);
// Only use the last AlignmentSpan with flag SPAN_PARAGRAPH
for (int i = alignmentSpans.length - 1; i >= 0; i--) {
AlignmentSpan s = alignmentSpans[i];
if ((text.getSpanFlags(s) & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH) {
final Layout.Alignment alignment = s.getAlignment();
if (alignment == Layout.Alignment.ALIGN_NORMAL) {
textAlign = "text-align:start;";
} else if (alignment == Layout.Alignment.ALIGN_CENTER) {
textAlign = "text-align:center;";
} else if (alignment == Layout.Alignment.ALIGN_OPPOSITE) {
textAlign = "text-align:end;";
}
break;
}
}
}
if (margin == null && textAlign == null) {
return "";
}
final StringBuilder style = new StringBuilder(" style=\"");
if (margin != null && textAlign != null) {
style.append(margin).append(" ").append(textAlign);
} else if (margin != null) {
style.append(margin);
} else if (textAlign != null) {
style.append(textAlign);
}
return style.append("\"").toString();
}
示例7: drawText
import android.text.Layout; //导入方法依赖的package包/类
private void drawText(Canvas canvas, String text, float x, float y, TextPaint paint, Layout.Alignment aligment) {
canvas.save();
{
canvas.translate(x, y);
final StaticLayout staticLayout = new StaticLayout(text, paint, (int) paint.measureText(text), aligment, 1.0f, 0, false);
staticLayout.draw(canvas);
}
canvas.restore();
}
示例8: drawMultilineText
import android.text.Layout; //导入方法依赖的package包/类
private void drawMultilineText(Canvas canvas, String text, float x, float y, TextPaint paint, Layout.Alignment aligment) {
final float lineHeight = paint.getTextSize();
float lineY = y;
for (CharSequence line : text.split("\n")) {
canvas.save();
{
final float lineWidth = (int) paint.measureText(line.toString());
float lineX = x;
if (aligment == Layout.Alignment.ALIGN_CENTER) {
lineX -= lineWidth / 2f;
}
if (lineX < 0) {
lineX = 0;
}
final float right = lineX + lineWidth;
if (right > canvas.getWidth()) {
lineX = canvas.getWidth() - lineWidth - settings.paddingCorners;
}
canvas.translate(lineX, lineY);
final StaticLayout staticLayout = new StaticLayout(line, paint, (int) lineWidth, aligment, 1.0f, 0, false);
staticLayout.draw(canvas);
lineY += lineHeight;
}
canvas.restore();
}
}
示例9: getTextAlignment
import android.text.Layout; //导入方法依赖的package包/类
public static Layout.Alignment getTextAlignment(Map<String, Object> style){
Layout.Alignment alignment= Layout.Alignment.ALIGN_NORMAL;
String textAlign= (String) style.get(Constants.Name.TEXT_ALIGN);
if(TextUtils.equals(Constants.Value.LEFT,textAlign)){
alignment= Layout.Alignment.ALIGN_NORMAL;
}
else if(TextUtils.equals(Constants.Value.CENTER,textAlign)){
alignment=Layout.Alignment.ALIGN_CENTER;
}
else if(TextUtils.equals(Constants.Value.RIGHT,textAlign)){
alignment= Layout.Alignment.ALIGN_OPPOSITE;
}
return alignment;
}
示例10: configure
import android.text.Layout; //导入方法依赖的package包/类
public void configure(float x, float y, float minXLeft, float maxXRight, Layout.Alignment alignment) {
this.alignment = alignment;
this.x = x;
this.y = y;
this.minXLeft = minXLeft;
this.maxXRight = maxXRight;
}
示例11: getLayoutAlignment
import android.text.Layout; //导入方法依赖的package包/类
public static Layout.Alignment getLayoutAlignment(View view, int gravity) {
Layout.Alignment alignment;
if (Build.VERSION.SDK_INT >= 17) {
switch (view.getTextAlignment()) {
case android.view.View.TEXT_ALIGNMENT_GRAVITY:
alignment = getAlignmentByGravity(gravity);
break;
case android.view.View.TEXT_ALIGNMENT_TEXT_START:
alignment = Layout.Alignment.ALIGN_NORMAL;
break;
case android.view.View.TEXT_ALIGNMENT_TEXT_END:
alignment = Layout.Alignment.ALIGN_OPPOSITE;
break;
case android.view.View.TEXT_ALIGNMENT_CENTER:
alignment = Layout.Alignment.ALIGN_CENTER;
break;
case android.view.View.TEXT_ALIGNMENT_VIEW_START:
alignment = (ViewCompat.getLayoutDirection(view) == LAYOUT_DIRECTION_RTL) ?
Layout.Alignment.ALIGN_RIGHT : Layout.Alignment.ALIGN_LEFT;
break;
case android.view.View.TEXT_ALIGNMENT_VIEW_END:
alignment = (ViewCompat.getLayoutDirection(view) == LAYOUT_DIRECTION_RTL) ?
Layout.Alignment.ALIGN_LEFT : Layout.Alignment.ALIGN_RIGHT;
break;
case android.view.View.TEXT_ALIGNMENT_INHERIT:
// This should never happen as we have already resolved the text alignment
// but better safe than sorry so we just fall through
default:
alignment = Layout.Alignment.ALIGN_NORMAL;
break;
}
return alignment;
} else {
return getAlignmentByGravity(gravity);
}
}
示例12: createStaticLayout
import android.text.Layout; //导入方法依赖的package包/类
public static StaticLayout createStaticLayout(CharSequence source, TextPaint paint, int width, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad, TextUtils.TruncateAt ellipsize, int ellipsisWidth, int maxLines) {
return createStaticLayout(source, 0, source.length(), paint, width, align, spacingmult, spacingadd, includepad, ellipsize, ellipsisWidth, maxLines);
}
示例13: setTextAlign
import android.text.Layout; //导入方法依赖的package包/类
public WebvttCssStyle setTextAlign(Layout.Alignment textAlign) {
this.textAlign = textAlign;
return this;
}
示例14: getTextAlign
import android.text.Layout; //导入方法依赖的package包/类
public Layout.Alignment getTextAlign() {
return textAlign;
}
示例15: createTextLayout
import android.text.Layout; //导入方法依赖的package包/类
private static Layout createTextLayout(
int width,
YogaMeasureMode widthMode,
TextUtils.TruncateAt ellipsize,
boolean shouldIncludeFontPadding,
int maxLines,
boolean isSingleLine,
CharSequence text,
int textSize,
float extraSpacing,
float spacingMultiplier,
int textStyle,
Layout.Alignment textAlignment) {
Layout newLayout;
final @TextLayoutBuilder.MeasureMode int textMeasureMode;
switch (widthMode) {
case UNDEFINED:
textMeasureMode = TextLayoutBuilder.MEASURE_MODE_UNSPECIFIED;
break;
case EXACTLY:
textMeasureMode = TextLayoutBuilder.MEASURE_MODE_EXACTLY;
break;
case AT_MOST:
textMeasureMode = TextLayoutBuilder.MEASURE_MODE_AT_MOST;
break;
default:
throw new IllegalStateException("Unexpected size mode: " + widthMode);
}
sTextLayoutBuilder
.setEllipsize(ellipsize)
.setMaxLines(maxLines)
.setSingleLine(isSingleLine)
.setText(text)
.setTextSize(textSize)
.setWidth(width, textMeasureMode);
sTextLayoutBuilder.setTextStyle(textStyle);
sTextLayoutBuilder.setTextDirection(TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR);
sTextLayoutBuilder.setIncludeFontPadding(shouldIncludeFontPadding);
sTextLayoutBuilder.setTextSpacingExtra(extraSpacing);
sTextLayoutBuilder.setTextSpacingMultiplier(spacingMultiplier);
sTextLayoutBuilder.setAlignment(textAlignment);
newLayout = sTextLayoutBuilder.build();
sTextLayoutBuilder.setText(null);
return newLayout;
}