开发者

How to know the number of pixels that a String is occupying?

开发者 https://www.devze.com 2023-04-03 08:13 出处:网络
I have an item ( TextField, or Text开发者_如何学运维Area, ...). It has a content value , say \"hello world\". How to know the number of pixels that this \"hello world\" String value is occupying on th

I have an item ( TextField, or Text开发者_如何学运维Area, ...). 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 ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消