Hi,viewpager + webview, come interrompere la visualizzazione web loading
Ho creato un'applicazione che utilizza ViewPager e tutte le pagine contengono WebViews. Ogni Webview contiene immagini di server, video, mp3 ...
Le impostazioni WebView sono
public Object instantiateItem(View collection, int position) {
.
.
.
final RelativeLayout imageLayout = (RelativeLayout)
inflater.inflate(R.layout.omb_webview_layout, null);
WebView webview = (WebView) imageLayout.findViewById(R.id.video_view);
ProgressBar pbImage = (ProgressBar) imageLayout.findViewById(R.id.progressBar1);
webview.requestFocus(View.FOCUS_DOWN);
webview.getSettings().setBuiltInZoomControls(false);
webview.getSettings().setSupportZoom(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.setWebViewClient(new mWebViewClient());
webview.getSettings().setPluginsEnabled(true);
webview.clearCache(true);
webview.clearHistory();
if(Pbar != null) {
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
Log.i(TAG, "webview loading progress : "+ progress);
if(progress == 100) {
try {
Pbar.setVisibility(ProgressBar.GONE);
} catch (Exception e) {
Log.e(TAG, "timer progress GONE : "+ progress,e);
}
}
});
}
Il problema è quando le pagine sono fregato poi anche questa linea
Log.i(TAG, "webview loading progress : "+ progress);
è di esecuzione che significa che le visualizzazioni web si stanno caricando in background. Se faccio scorrere 4 o più pagine, tutte le immagini web si stanno caricando.
destroyItem(View collection, int position, Object o) {
Log.d("DESTROY", "destroying view at position sheetal " + position);
RelativeLayout view = (RelativeLayout)o;
WebView tmp = webviewDictionary.get(position);;
tmp.getSettings().setJavaScriptEnabled(false);
tmp.stopLoading();
if(tmp != null){
Log.i(TAG, "sheetal webview is destroyed " +position);
try {
tmp.onPause();
tmp.loadDataWithBaseURL("about:blank", "<html></html>","text/html", "UTF-8", null);
tmp=null;
// tmp.destroy();
}
catch (Exception e) {
Log.i(TAG, "webview destroyed Exception 0" ,e);
}
}
Come interrompere il caricamento in background se le pagine non sono visibili? setOffscreenPageLimit (1) (significa 3 pagine prev, cur, next),
In Viewpager, 2 pagine (significa pagina 1 posizione) non si carica correttamente. Mostra una pagina bianca vuota, come posso risolverlo?
Grazie in anticipo
ho usato StopLoading(), ma dose non fermano il caricamento in background, ogni volta che destroyItem (.. .) si chiama webview interrompere il caricamento giusto? ma non smettere di caricare. –
Non completamente sicuro, ma non è necessario impostare OffscreenPageLimit su 0? – THelper
ho provato pager.OffscreenPageLimit (0) ma non funziona. –