android 阅读器分页读取字数
16lz
2021-01-23
// 本方法 分行又分页public static ArrayList<ArrayList<String>> getPageContentStringInfo( Paint m_paint, String content, int pageLines, float pageWidth) { char ch; int w = 0; int istart = 0; int lineNum = 0; ArrayList<ArrayList<String>> contentList = new ArrayList<ArrayList<String>>(); ArrayList<String> cl = null; // 内容长度 for (int i = 0; i < content.length(); i++) { if (cl == null) cl = new ArrayList<String>(); ch = content.charAt(i); float[] widths = new float[1]; String srt = String.valueOf(ch); m_paint.getTextWidths(srt, widths); if (ch == '\n') { // 如果遇到断行符 lineNum++; cl.add(content.substring(istart, i)); istart = i + 1; w = 0; } else { // 遇到字符 w += (int) (Math.ceil(widths[0])); // 当长度小于宽度时 if (w > pageWidth) { lineNum++; cl.add(content.substring(istart, i)); istart = i; i--; w = 0; } else { if (i == (content.length() - 1)) { lineNum++; cl.add(content.substring(istart, content.length())); } } } if (lineNum == pageLines || i == (content.length() - 1)) { contentList.add(cl); System.out.println(cl.toString()); cl = null; // 当最后一个字符时的行数 lines = lineNum; lineNum = 0; } } return contentList; }
更多相关文章
- Android EditText插入字符串到光标所在位置和删除
- android非法字符的判定、表情符号的判定
- Android将获取到文件的uri转换为字符串的路径
- android XML文件常用字符转义
- Android 创建一个包含星期的格式字符串
- Android源码快速查找文件、搜索字符串和编译
- android上传图片以及POST字符串
- android调用webservice方法,参数和返回值都用字符串
- android 发送短信 判断号码规则 判断字符数70