gpt4 book ai didi

android - 获取 TextView 中文本的大小

转载 作者:IT王子 更新时间:2023-10-29 00:00:26 32 4
gpt4 key购买 nike

我在将 textView 放置在指定中心的 x 和 y 坐标时遇到问题。首先,我尝试在 textView 中设置文本,并以 View 的宽度和高度移动 View from this link .

但它不起作用,我想尝试其他方法。我想知道是否有一种方法可以获取指定文本在我的 textView 中的大小?我的意思是,我知道 text 和 textSize,如何获得 textView 的宽度和高度?

类似于 (NSString)sizeWithFont; 的方法,适合那些了解 iPhone 开发的人。

最佳答案

Rect bounds = new Rect();

textView.getPaint().getTextBounds(textView.getText().toString(), 0, textView.getText().length(), bounds);

bounds.width() 将为您提供 TextView 中文本的准确宽度。

关于android - 获取 TextView 中文本的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6734301/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com