检查String(TextView)是否没有足够的空间

时间:2012-12-13 19:26:43

标签: android

是否有可能检查String上分配的TextView长度是否比实际设备的屏幕更长?换句话说,如何检查文本是否适合屏幕?

如果文字不合适,我需要的是释放一些空间。

1 个答案:

答案 0 :(得分:0)

你可以在上面调用措施。

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

取自问题/答案here

然后您可以使用该测量值与屏幕尺寸进行比较。