我一直在android中使用epublib来加载webview中的epub文件。这是我加载文件的代码
public void getEntireBook(){
Spine spine = book.getSpine();
List<SpineReference> spineList = spine.getSpineReferences() ;
int count = spineList.size();
TextView tv=new TextView(getApplicationContext());
tv.setText(Integer.toString(count));
StringBuilder string = new StringBuilder();
for (int i = 0; count > i; i++) {
Resource res = spine.getResource(i);
string.append(res.getTitle());
RowData row = new RowData();
row.setTitle(string.toString());
row.setResource(spine.getResource(i));
contentDetails.add(row);
try {
InputStream is = res.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
while ((line =(String) reader.readLine()) != null) {
}
} catch (IOException e) {e.printStackTrace();}
//do something with stream
} catch (IOException e) {
e.printStackTrace();
}
webView.loadData(line, "text/html;charset=UTF-8",null);
}
}
有些文件加载正常,20 mb到70 mb的文件加载得很好但是90 mb以上的文件会出现问题,要么显示空白webview,要么屏幕变黑。
有些文件的另一个问题是某些文件有大文本,并且有丰富的图形内容,如图片,装饰字体。当我在webview中加载它们时会显示小点,当我放大文本时会分散。
所以我有两个问题
我已经使用了像setrenderpriority等所有的webview设置,将js注入webview但我无法找到解决方案。
答案 0 :(得分:1)
你应该逐章(分页)。不要一次渲染所有章节,这可能会使android变得迟钝。
public void pagination (int page){
Resource res = spine.getResource(page);
string.append(res.getTitle());
RowData row = new RowData();
row.setTitle(string.toString());
row.setResource(res);
contentDetails.add(row);
try {
InputStream is = res.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
while ((line =(String) reader.readLine()) != null) {
}
} catch (IOException e) {e.printStackTrace();}
//do something with stream
} catch (IOException e) {
e.printStackTrace();
}
webView.loadData(line, "text/html;charset=UTF-8",null);
}