如何知道字符串占用的像素数?

发布于 2024-12-03 10:29:58 字数 90 浏览 0 评论 0原文

我有一个项目(TextField 或 TextArea,...)。它具有内容价值,说“你好世界”。如何知道这个“hello world”字符串值在屏幕上占用的像素数?

I have an item ( TextField, or TextArea, ...). It has a content value , say "hello world". How to know the number of pixels that this "hello world" String value is occupying on the screen ?

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

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

发布评论

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

评论(1

怀里藏娇 2024-12-10 10:29:58

您可以获得首选宽度/高度以进行粗略估计(您还需要添加边距以获得准确的尺寸)。然而,布局管理器将这些视为指导方针,而不是最终尺寸,并且可以决定将组件放置在任何地方。

在运行时(例如绘制等)期间,getX/Y/Width/Height 参数提供准确的组件尺寸和位置。但是,这些仅对当前绘制操作有效,因为设备可能会旋转或可能需要布局回流。

您需要更具体地说明您想要实现的目标。

You can get the preferred width/height to get a rough estimation (you would also need to add the margin's to get accurate sizing). However the layout manager views these as guidelines not as final sizes and can decide on placing a component anywhere.

During runtime e.g. paint etc. the getX/Y/Width/Height argument provide accurate component size and position. However, these are only valid for the current paint operation since a device may be rotated or might require layout reflow.

You need to be more specific on what you are trying to accomplish.

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