2011-07-12 64 views
4

我想在webview中向下滾動到頁面的底部,我使用的是在他們的教程中提供的webview示例谷歌。我使用這行代碼嘗試滾動,但它不起作用。 mWebView.pageDown(真); 關於如何以編程方式進行滾動的任何建議?謝謝。Android的webview滾動不起作用

public class WebViewExample extends Activity { 

private static final String LOG_TAG = "WebViewDemo"; 

private WebView mWebView; 

private Handler mHandler = new Handler(); 

@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.main); 
    mWebView = (WebView) findViewById(R.id.webview); 

    WebSettings webSettings = mWebView.getSettings(); 
    webSettings.setSavePassword(false); 
    webSettings.setSaveFormData(false); 
    webSettings.setJavaScriptEnabled(true); 
    webSettings.setSupportZoom(false); 

    mWebView.setWebChromeClient(new MyWebChromeClient()); 

    mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo"); 

    mWebView.loadUrl("http://www.google.com/search?q=android+webview+scroll+doesnt+work&hl=en&safe=off&prmd=ivns&ei=0b0cTquNNI6WsgP6l7igBQ&start=10&sa=N#sclient=psy&hl=en&safe=off&source=hp&q=android%20webview%20scrollable&pbx=1&oq=&aq=&aqi=&aql=&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.&fp=c306e119a7d85f91&biw=1280&bih=738&pf=p&pdl=300"); 

      //this is where I try to scroll, doesn't work 
      mWebView.pageDown(true); 

} 

final class DemoJavaScriptInterface { 

    DemoJavaScriptInterface() { 
    } 

    /** 
    * This is not called on the UI thread. Post a runnable to invoke loadUrl on the UI thread. 
    */ 
    public void clickOnAndroid() { 
     mHandler.post(new Runnable() { 
      @Override 
      public void run() { 
       mWebView.loadUrl("javascript:wave()"); 
      } 
     }); 

    } 
} 

/** 
* Provides a hook for calling "alert" from javascript. Useful for debugging your javascript. 
*/ 
final class MyWebChromeClient extends WebChromeClient { 
    @Override 
    public boolean onJsAlert(WebView view, String url, String message, JsResult result) { 
     Log.d(LOG_TAG, message); 
     result.confirm(); 
     return true; 
    } 
} 

}

回答

0

我認爲應該mWebView.pageDown(true);裝載後的內容調用。

mWebview.setWebViewClient(new WebViewClient() { 
    public void onPageFinished (WebView view, String url) { 
     mWebView.pageDown(true); 
    } 
});