Android webview滚动不起作用

时间:2011-07-12 23:07:33

标签: java android

我正在尝试在webview中向下滚动到页面底部,我正在使用他们的教程中提供的webview示例。我正在使用这行代码尝试滚动但它无法正常工作。 mWebView.pageDown(真); 有关如何使其以编程方式滚动的任何建议?谢谢。

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;
    }
}

}

1 个答案:

答案 0 :(得分:0)

我认为在加载内容后应该调用mWebView.pageDown(true);

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