TextView - 如何使第二行缩进

发布于 2024-10-03 13:29:44 字数 101 浏览 0 评论 0原文

我想让 TextView 的第二行(以及第三行、第四行等)缩进,这可能吗?我事先不知道 TextView 的确切文本。文本将不包含换行符(“\n”) - TextView 将自动将其换行。

I want to have the second line (and third, fourth, etc.) of my TextView indented, is that possible? I don't know the exact TextView's text in advance. The text will be without newline ("\n") characters - it will be wrapped to lines automatically by the TextView.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如梦亦如幻 2024-10-10 13:29:49
public static void IndentEffect(WebView webViewv, String string) {
    webViewv.loadData("<html><p style=\"padding-left: 40px;text-indent: -20px;\">" + string.toUpperCase() + "</p></html>", "text/html", "utf-8");
    WebSettings webSettings = webViewv.getSettings();
    webSettings.setTextZoom(webSettings.getTextZoom() + 20);
}

对于上面的包装方法,如果您只传递 webview 引用和占位符文本,那么所需的缩进将自动应用于第二行。

一切顺利 !!可能对有需要的人有帮助。

public static void IndentEffect(WebView webViewv, String string) {
    webViewv.loadData("<html><p style=\"padding-left: 40px;text-indent: -20px;\">" + string.toUpperCase() + "</p></html>", "text/html", "utf-8");
    WebSettings webSettings = webViewv.getSettings();
    webSettings.setTextZoom(webSettings.getTextZoom() + 20);
}

For the above wrapper method, if you just pass the webview reference and the place holder text, then the required indentation will be automatically applied for the second line.

ALL THE BEST !! Might be helpful for someone in need.

嗫嚅 2024-10-10 13:29:49

我觉得你需要使用多个 TextView。一个具有全宽度,然后另一个在其正下方,左侧有一些填充或边距,以产生缩进的外观。

在您的代码中,您必须解析文本,以便只有一定数量的字符进入顶部 TextView,其余的字符进入下面。

这不是最好的解决方案,但可能值得一试。如果您打算这样做,您肯定会想使用等宽字体。这样,第一个 TextView 中的单行将始终具有相同数量的字符。

I feel like you would need to use multiple TextViews. One with a full width and then another one right below it with some padding or margin on the left to give the appearance of an indentation.

In your code you'd have to parse the text so that only a certain number of characters go into the top TextView, and the rest go below.

Not the greatest solution, but it might be worth playing with. If you're going to do it this way you would definitely want to use a mono spaced font. That way you would always have the same number of characters that could fit on a single line in the first TextView.

勿挽旧人 2024-10-10 13:29:47

另一种可能性是从 TextView 切换到 WebView,然后使用 CSS 将文本的 padding-left 设置为 20px,将 text-indent 设置为 -20px。这应该将所有文本移动 20 像素,除了第一行将被拉回 20 像素。

Another possibility would be to switch from a TextView to a WebView then using CSS set the padding-left of your text to 20px and text-indent to -20px. That should move all text in 20px except the first line which will be pulled back 20px.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文