3 回答

TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
幾年來,我成功地將Richard的答案與PictureListener結(jié)合使用,但是我不再建議將其作為最佳解決方案。
這有兩個(gè)原因:
webView.setPictureListener和PictureListener都棄用。
使用此偵聽器將導(dǎo)致WebView經(jīng)常分配新圖片。這種分配非常昂貴,并且可能會(huì)對(duì)性能產(chǎn)生重大影響,甚至導(dǎo)致JellyBean MR1發(fā)生本機(jī)崩潰。
相反,我建議創(chuàng)建WebView的子類并覆蓋invalidate(),如下所示:
@Override
public void invalidate() {
super.invalidate();
if (getContentHeight() > 0) {
// WebView has displayed some content and is scrollable.
}
}
如果仍要使用PictureListener方法,則在將其設(shè)置為null之后將其設(shè)置為null將獲得更好的性能。

TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個(gè)贊
自從我第一次發(fā)布此內(nèi)容以來,Android API 12中已不推薦使用此方法。感謝Google!我會(huì)保留原始答案:
是的-有一個(gè)偵聽器,用于了解內(nèi)容何時(shí)完成加載。我必須在我的項(xiàng)目上創(chuàng)建一個(gè),這樣我才能做一個(gè)初始屏幕,直到Webview加載頁(yè)面為止。
它稱為.setPictureListener。
例如:
mWebView.setPictureListener(new MyPictureListener());
//... and then later on....
class MyPictureListener implements PictureListener {
@Override
public void onNewPicture(WebView view, Picture arg1) {
// put code here that needs to run when the page has finished loading and
// a new "picture" is on the webview.
}
}
- 3 回答
- 0 關(guān)注
- 547 瀏覽
添加回答
舉報(bào)