本文整理汇总了Java中android.text.StaticLayout.getLineLeft方法的典型用法代码示例。如果您正苦于以下问题:Java StaticLayout.getLineLeft方法的具体用法?Java StaticLayout.getLineLeft怎么用?Java StaticLayout.getLineLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.StaticLayout
的用法示例。
在下文中一共展示了StaticLayout.getLineLeft方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateStaticLayout
import android.text.StaticLayout; //导入方法依赖的package包/类
public static StaticLayout generateStaticLayout(CharSequence text, TextPaint paint, int maxWidth, int smallWidth, int linesCount, int maxLines) {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
int addedChars = 0;
StaticLayout layout = new StaticLayout(text, paint, smallWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
for (int a = 0; a < linesCount; a++) {
Layout.Directions directions = layout.getLineDirections(a);
if (layout.getLineLeft(a) != 0 || layout.isRtlCharAt(layout.getLineStart(a)) || layout.isRtlCharAt(layout.getLineEnd(a))) {
maxWidth = smallWidth;
}
int pos = layout.getLineEnd(a);
if (pos == text.length()) {
break;
}
pos--;
if (stringBuilder.charAt(pos + addedChars) == ' ') {
stringBuilder.replace(pos + addedChars, pos + addedChars + 1, "\n");
} else if (stringBuilder.charAt(pos + addedChars) != '\n') {
stringBuilder.insert(pos + addedChars, "\n");
addedChars++;
}
if (a == layout.getLineCount() - 1 || a == maxLines - 1) {
break;
}
}
return StaticLayoutEx.createStaticLayout(stringBuilder, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, dp(1), false, TextUtils.TruncateAt.END, maxWidth, maxLines);
}
示例2: setTitle
import android.text.StaticLayout; //导入方法依赖的package包/类
public void setTitle(String title) {
stringBuilder.setLength(0);
if (title != null && title.length() > 0) {
stringBuilder.append(title.substring(0, 1));
}
if (stringBuilder.length() > 0) {
String text = stringBuilder.toString().toUpperCase();
try {
textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (textLayout.getLineCount() > 0) {
textLeft = textLayout.getLineLeft(0);
textWidth = textLayout.getLineWidth(0);
textHeight = textLayout.getLineBottom(0);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else {
textLayout = null;
}
}
示例3: createLayout
import android.text.StaticLayout; //导入方法依赖的package包/类
private void createLayout(int width) {
if (text != null) {
try {
CharSequence string = TextUtils.ellipsize(text, textPaint, width, TextUtils.TruncateAt.END);
layout = new StaticLayout(string, 0, string.length(), textPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
/*if (metrics == null) {
metrics = BoringLayout.isBoring(text, textPaint);
}
if (layout == null) {
layout = BoringLayout.make(text, textPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, metrics, false, TextUtils.TruncateAt.END, width);
} else {
layout = ((BoringLayout) layout).replaceOrMake(text, textPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, metrics, false, TextUtils.TruncateAt.END, width);
}*/
/*if (spannableStringBuilder == null) {
spannableStringBuilder = new SpannableStringBuilder(text);
layout = new DynamicLayout(text, text, textPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false, TextUtils.TruncateAt.END, width);
} else {
spannableStringBuilder.replace(0, text.length(), text);
}*/
if (layout.getLineCount() > 0) {
if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.LEFT) {
offsetX = -(int) layout.getLineLeft(0);
} else if (layout.getLineLeft(0) == 0) {
offsetX = (int) (width - layout.getLineWidth(0));
} else {
offsetX = 0;
}
}
} catch (Exception e) {
//ignore
}
}
}
示例4: drawTextLayout
import android.text.StaticLayout; //导入方法依赖的package包/类
private void drawTextLayout(Canvas canvas) {
StaticLayout layout = textLayout;
if (layout == null) {
// Nothing to draw.
return;
}
int saveCount = canvas.save();
canvas.translate(textLeft, textTop);
if (Color.alpha(windowColor) > 0) {
paint.setColor(windowColor);
canvas.drawRect(-textPaddingX, 0, layout.getWidth() + textPaddingX, layout.getHeight(),
paint);
}
if (Color.alpha(backgroundColor) > 0) {
paint.setColor(backgroundColor);
float previousBottom = layout.getLineTop(0);
int lineCount = layout.getLineCount();
for (int i = 0; i < lineCount; i++) {
lineBounds.left = layout.getLineLeft(i) - textPaddingX;
lineBounds.right = layout.getLineRight(i) + textPaddingX;
lineBounds.top = previousBottom;
lineBounds.bottom = layout.getLineBottom(i);
previousBottom = lineBounds.bottom;
canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint);
}
}
if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) {
textPaint.setStrokeJoin(Join.ROUND);
textPaint.setStrokeWidth(outlineWidth);
textPaint.setColor(edgeColor);
textPaint.setStyle(Style.FILL_AND_STROKE);
layout.draw(canvas);
} else if (edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) {
textPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, edgeColor);
} else if (edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED
|| edgeType == CaptionStyleCompat.EDGE_TYPE_DEPRESSED) {
boolean raised = edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED;
int colorUp = raised ? Color.WHITE : edgeColor;
int colorDown = raised ? edgeColor : Color.WHITE;
float offset = shadowRadius / 2f;
textPaint.setColor(foregroundColor);
textPaint.setStyle(Style.FILL);
textPaint.setShadowLayer(shadowRadius, -offset, -offset, colorUp);
layout.draw(canvas);
textPaint.setShadowLayer(shadowRadius, offset, offset, colorDown);
}
textPaint.setColor(foregroundColor);
textPaint.setStyle(Style.FILL);
layout.draw(canvas);
textPaint.setShadowLayer(0, 0, 0, 0);
canvas.restoreToCount(saveCount);
}
示例5: setInfo
import android.text.StaticLayout; //导入方法依赖的package包/类
public void setInfo(int id, String firstName, String lastName, boolean isBroadcast) {
if (isProfile) {
color = arrColorsProfiles[getColorIndex(id)];
} else {
color = arrColors[getColorIndex(id)];
}
drawBrodcast = isBroadcast;
if (firstName == null || firstName.length() == 0) {
firstName = lastName;
lastName = null;
}
stringBuilder.setLength(0);
if (firstName != null && firstName.length() > 0) {
stringBuilder.append(firstName.substring(0, 1));
}
if (lastName != null && lastName.length() > 0) {
String lastch = null;
for (int a = lastName.length() - 1; a >= 0; a--) {
if (lastch != null && lastName.charAt(a) == ' ') {
break;
}
lastch = lastName.substring(a, a + 1);
}
if (Build.VERSION.SDK_INT >= 16) {
stringBuilder.append("\u200C");
}
stringBuilder.append(lastch);
} else if (firstName != null && firstName.length() > 0) {
for (int a = firstName.length() - 1; a >= 0; a--) {
if (firstName.charAt(a) == ' ') {
if (a != firstName.length() - 1 && firstName.charAt(a + 1) != ' ') {
if (Build.VERSION.SDK_INT >= 16) {
stringBuilder.append("\u200C");
}
stringBuilder.append(firstName.substring(a + 1, a + 2));
break;
}
}
}
}
if (stringBuilder.length() > 0) {
String text = stringBuilder.toString().toUpperCase();
try {
textLayout = new StaticLayout(text, (smallStyle ? namePaintSmall : namePaint), AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (textLayout.getLineCount() > 0) {
textLeft = textLayout.getLineLeft(0);
textWidth = textLayout.getLineWidth(0);
textHeight = textLayout.getLineBottom(0);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else {
textLayout = null;
}
}
示例6: createStaticLayout
import android.text.StaticLayout; //导入方法依赖的package包/类
public static StaticLayout createStaticLayout(CharSequence source, int bufstart, int bufend, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsisWidth, int maxLines) {
/*if (Build.VERSION.SDK_INT >= 14) {
init();
try {
sConstructorArgs[0] = source;
sConstructorArgs[1] = bufstart;
sConstructorArgs[2] = bufend;
sConstructorArgs[3] = paint;
sConstructorArgs[4] = outerWidth;
sConstructorArgs[5] = align;
sConstructorArgs[6] = sTextDirection;
sConstructorArgs[7] = spacingMult;
sConstructorArgs[8] = spacingAdd;
sConstructorArgs[9] = includePad;
sConstructorArgs[10] = ellipsize;
sConstructorArgs[11] = ellipsisWidth;
sConstructorArgs[12] = maxLines;
return sConstructor.newInstance(sConstructorArgs);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}*/
try {
if (maxLines == 1) {
CharSequence text = TextUtils.ellipsize(source, paint, ellipsisWidth, TextUtils.TruncateAt.END);
return new StaticLayout(text, 0, text.length(), paint, outerWidth, align, spacingMult, spacingAdd, includePad);
} else {
StaticLayout layout = new StaticLayout(source, paint, outerWidth, align, spacingMult, spacingAdd, includePad);
if (layout.getLineCount() <= maxLines) {
return layout;
} else {
int off;
float left = layout.getLineLeft(maxLines - 1);
if (left != 0) {
off = layout.getOffsetForHorizontal(maxLines - 1, left);
} else {
off = layout.getOffsetForHorizontal(maxLines - 1, layout.getLineWidth(maxLines - 1));
}
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(source.subSequence(0, Math.max(0, off - 1)));
stringBuilder.append("\u2026");
return new StaticLayout(stringBuilder, paint, outerWidth, align, spacingMult, spacingAdd, includePad);
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return null;
}