如何获得TextView中的行数渲染过吗?如何获得、行数、TextView

由网友(じ False“ 一直都在)分享简介:我怎样才能获得的行数的字符串将在一个的TextView 被渲染之前。 A ViewTreeObserver 将无法工作,因为这些被渲染后,仅启动。解决方案 矩形边界=新的矩形();涂料粉刷=新的油漆();paint.setTextSize(currentSize);paint.getTextBounds(的...

我怎样才能获得的行数的字符串将在一个的TextView 被渲染之前。

A ViewTreeObserver 将无法工作,因为这些被渲染后,仅启动。

解决方案

 矩形边界=新的矩形();
涂料粉刷=新的油漆();
paint.setTextSize(currentSize);
paint.getTextBounds(的TestString,0,testString.length(),边界);

INT宽度=(int)的Math.ceil(bounds.width());
 

现在devide文本的宽度与你的TextView的宽度,并得到总线路。

How can I get the number of lines a string will take up in a TextView before it is rendered.

如何将ZTE手机设置为中文输入法

A ViewTreeObserver will not work because those are only fired after it is rendered.

解决方案

Rect bounds = new Rect();
Paint paint = new Paint();
paint.setTextSize(currentSize);
paint.getTextBounds(testString, 0, testString.length(), bounds);

int width = (int) Math.ceil( bounds.width());

Now devide the width of text with the width of your TextView and get the total lines.

阅读全文

相关推荐

最新文章