根据字符串的长度得到其在屏幕上的px值
/** * 根据字符串的长度得到其在屏幕上的px值 * * @param textView * @param nameFormat * @param start * @param end * @return */ private int getPxByTextLength(TextView textView, String nameFormat, int start, int end) { if (nameWidthList == null) { nameWidthList = new ArrayList<>(); } Rect bounds = new Rect(); TextPaint paint = textView.getPaint(); paint.getTextBounds(nameFormat, start, end, bounds); final int width = bounds.width(); System.out.println("parseText width = " + width); nameWidthList.add(width); return width; }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: PHP的页面布局怎样设计
- 下一篇: js求出字符所占像素及截取字符串
