中英文排版怎么弄
llxqb opened this issue · 3 comments
llxqb commented
中英文排版怎么弄
newbiechen1024 commented
当前项目要支持的话,需要使用 StaticLayout 检测换行,在 PageLoader 的行字数检测中:
//测量一行占用的字节数
if (showTitle) {
wordCount = mTitlePaint.breakText(paragraph,
true, mVisibleWidth, null);
} else {
wordCount = mTextPaint.breakText(paragraph,
true, mVisibleWidth, null);
}
替换成 StaticLayout 进行测量一行的字数,类似下面的代码:
private int getLineMaxNumber(String text, TextPaint paint, int maxWidth) {
if (null == text || "".equals(text)) {
return 0;
}
StaticLayout staticLayout = new StaticLayout(text, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL
, 1.0f, 0, false);
//获取第一行最后显示的字符下标
return staticLayout.getLineEnd(0);
}
cuijigang commented
作者把内容全部转换为了全角字符,是不是因为这个原因?
luotext commented
当前项目要支持的话,需要使用 StaticLayout 检测换行,在 PageLoader 的行字数检测中:
//测量一行占用的字节数 if (showTitle) { wordCount = mTitlePaint.breakText(paragraph, true, mVisibleWidth, null); } else { wordCount = mTextPaint.breakText(paragraph, true, mVisibleWidth, null); }
替换成 StaticLayout 进行测量一行的字数,类似下面的代码:
private int getLineMaxNumber(String text, TextPaint paint, int maxWidth) { if (null == text || "".equals(text)) { return 0; } StaticLayout staticLayout = new StaticLayout(text, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL , 1.0f, 0, false); //获取第一行最后显示的字符下标 return staticLayout.getLineEnd(0); }
那我有个疑问喔,就是如果是整体的文章都是英文呢?这个排版,单词不会被切割吗?