由网友(じ False“ 一直都在)分享简介:我怎样才能获得的行数的字符串将在一个的TextView 被渲染之前。 A ViewTreeObserver 将无法工作,因为这些被渲染后,仅启动。解决方案 矩形边界=新的矩形();涂料粉刷=新的油漆();paint.setTextSize(currentSize);paint.getTextBounds(的...![如何将ZTE手机设置为中文输入法](/d/file/2023/09-17/53163b72abc8efb0463bf31de211cea9.png)
我怎样才能获得的行数的字符串将在一个的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手机设置为中文输入法](/d/file/2023/09-17/53163b72abc8efb0463bf31de211cea9.png)
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.
相关推荐
最新文章