获取TextView中文字的大小 [英] Get the size of a text in TextView

查看:162
本文介绍了获取TextView中文字的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题放置一个TextView在指定中心的X和Y坐标。 首先,我试图设置TextView的文本,并与时宽度的观点和看法的高度 <一href="http://stackoverflow.com/questions/6653359/how-to-move-a-textview-to-an-x-and-an-y-in-a-relativelayout/6654371#6654371">from此链接。

I have a problem placing a textView at specified center's x and y coordinates. Firstly, I tried to set the text in the textView, and to move the view with the width and the height of the view from this link.

但它不工作,我想尝试别的东西。 我想知道是否有一个方法来获得其指定的文本将在我的TextView的大小? 我的意思是,我知道文字和TEXTSIZE,我怎么能得到的宽度和高度我的TextView将采取?

But it doesn't work, and I'd like to try something else. I'd like to know if there is a method to get the size which a specified text will take in my textView? I mean, I know the text and the textSize, how can I get the width and the height my textView will take?

喜欢的东西的方法(的NSString)sizeWithFont; 对于那些谁知道iPhone开发

Something like the method (NSString)sizeWithFont; for those who know iPhone dev.

推荐答案

如果您的TextView被称为电视

If your textview is called TV

TV.setText("bla");
TV.measure(0, 0);       //must call measure!
TV.getMeasuredHeight(); //get height
TV.getMeasuredWidth();  //get width

更多关于这个(更新): 如何获得宽度/高度查看

这篇关于获取TextView中文字的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆