Android - 如何检查文本是否完全适合视图?
我有一系列按钮和文本视图,我希望它们始终是方形的,并且始终适合其中的文本量。如果视图中有一个单词,它将是一个小方块。如果视图有一个完整的句子,它将是一个足以容纳整个句子的正方形。
如何检查文本是否适合水平和垂直视图?我只看到了检查第一行文本是否水平适合视图的功能。但是,如果第一行文本适合而第二行或第三行被切断怎么办?我如何判断代码中是否发生了这种情况,以便我可以增加视图的大小?
谢谢!
I have a series of buttons and textviews that I would like to always be square and always fit the amount of text inside them. If the view has one word in it, it will be a small square. If the view has a whole sentence, it will be a square large enough to fit the entire sentence.
How can I check if text fits inside a view both horizontally AND vertically? I've only seen the ability to check if the first line of text fits in a view horizontally. But what if the first line of text fits and the second or third line gets cut off? How can I tell if that is happening in code so that I can increase the size of the view?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有文本,则可以使用 android:text="text" 添加文本,并检查它是否正确适合 XML 文件的图形视图,并调整屏幕尺寸。您还可以使用文本的相对大小,如像素 (px),以便在不同的屏幕上更加灵活
If you have the text you can add your text with android:text="text" and review if it fits correctly on your graphical view of the XML file, playing with the screen sizes. Also you can use a relative size for the text like pixels (px) to be more flexible with different screens