Android 开发:行间距与行编号
在我的应用程序中,我的 EditText 左侧有行号 - 到目前为止一切都很好,行号与 EditText 的行完全对齐。
问题是,如果用户更改 EditText 的文本大小,行号将无法正确对齐。所以我添加了代码,以便当 EditText 的文本大小更改时,行号文本大小也会更改;但这会导致另一个问题:如果用户选择较大的文本大小,则行号会占用所有空间,因此 EditText 中几乎没有任何空间可写入。
唯一的解决方案是设置行间距。所以我最终遇到了 setLineSpacing() 函数,并尝试根据教程使用它,但我不明白它是如何工作的,也无法让它与 EditText 的行对齐。
有人可以帮助我了解如何使用它,或者建议一种不同的方法来使行号 TextView 中的每一行与 EditText 的行对齐?
抱歉,如果这令人困惑,我不太擅长解释事情叹气。
谢谢, 亚历克斯.
In my app I have line numbers to the left of an EditText - everything is great so far, the line numbers are perfectly aligned with the lines of the EditText.
The problem is, if the user changes the text size of the EditText the line numbers aren't aligned properly. So I've added code so when the text size of the EditText is changed, the line numbers text size is changed too; but that causes another problem: if the user picks a big text size, the line numbers hog all the space, so there's barely any room to write in the EditText.
The only solution would be to set line spacing. So I eventually came across the setLineSpacing() function, and have tried using it based off tutorials but I don't understand how it works and can't get it aligned with the EditText's lines.
Can someone help me understand how to use it, or suggest a different way of getting each line in the line numbers TextView aligned with the EditText's lines?
Sorry if this is confusing, I'm not very good at explaining things well sigh.
Thanks,
Alex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我过去也遇到过类似的情况,其中
EditText
的大小受到限制。决定可以选择的最大字体大小应限制在视觉外观不难看的值。我觉得堵住可能发生但没有意义的情况是没有用的。最好阻止此类情况。也许你可以沿着这些思路思考。HTH,
阿克谢
I faced a similar situation in the past, in which the
EditText
's size was limited. It was decided that the max font size that can be chosen should be limited to a value in which the visual appearance does not look ugly. I feel it is useless to plug cases that can occur but don't make sense. It is better to block such cases. Perhaps you can think along these lines.HTH,
Akshay