牛骨文教育服务平台(让学习变的简单)
博文笔记

根据字符串的长度得到其在屏幕上的px值

创建时间:2016-03-21 投稿人: 浏览次数:158
/**
 * 根据字符串的长度得到其在屏幕上的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;
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。