Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

中英文排版怎么弄 #87

Open
llxqb opened this issue Mar 19, 2020 · 3 comments
Open

中英文排版怎么弄 #87

llxqb opened this issue Mar 19, 2020 · 3 comments

Comments

@llxqb
Copy link

llxqb commented Mar 19, 2020

No description provided.

@newbiechen1024
Copy link
Owner

当前项目要支持的话,需要使用 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
Copy link

作者把内容全部转换为了全角字符,是不是因为这个原因?

@luotext
Copy link

luotext commented Jul 4, 2020

当前项目要支持的话,需要使用 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);
    }

那我有个疑问喔,就是如果是整体的文章都是英文呢?这个排版,单词不会被切割吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants