本文整理汇总了Java中android.text.StaticLayout.getOffsetForHorizontal方法的典型用法代码示例。如果您正苦于以下问题:Java StaticLayout.getOffsetForHorizontal方法的具体用法?Java StaticLayout.getOffsetForHorizontal怎么用?Java StaticLayout.getOffsetForHorizontal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.StaticLayout
的用法示例。
在下文中一共展示了StaticLayout.getOffsetForHorizontal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}