下页(真)总是返回虚假的WebView安卓 [英] pageDown(true) always returning false in WebView Android

查看:122
本文介绍了下页(真)总是返回虚假的WebView安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的一个web视图,存储的谈话流我的应用程序。

每20秒应用程序轮询服务器的任何消息和更新的WebView。

每次的WebView更新它向后滚动到视图的顶部。

我想阻止这种情况发生,所以我试着用webView.pageDown(真正的);但是这似乎总是返回false。

任何帮助将是非常美联社preciated。这里是code:

  webView.loadDataWithBaseURL(假货://不是/必要,HTML,text / html的,UTF-8,);
    布尔滚动= webView.pageDown(真正的);
    的System.out.println(滚动是:+滚动);
 

解决方案

我有同样的问题,所以进一步的调查,发现这些人,相关型号:

  • <一个href="http://stackoverflow.com/questions/5644346/why-android-webview-pagedown-method-returns-false">why机器人的WebView下页()方法返回false?
  • <一个href="http://stackoverflow.com/questions/10064622/fix-scrollbar-to-bottom-of-web-view-in-android">Fix滚动条的Web视图底部的Andr​​oid

我设法想出的唯一解决方案是创建一个处理程序,将延迟呼吁webView.pageDown(真)为100ms的,然后它的作品。它可能需要更少或更多的时间,大概取决于web视图组件需要呈现给定的HTML的时间。

下面是code负载并滚动:

  webView.loadDataWithBaseURL(假货://不是/必要,HTML,text / html的,UTF-8,);
mWebViewScrollHandler.removeCallbacks(mScrollWebViewTask);
mWebViewScrollHandler.postDelayed(mScrollWebViewTask,100);
 

下面是code的处理程序:

 私人最终处理程序mWebViewScrollHandler =新的处理程序();

私人最终可运行mScrollWebViewTask =新的Runnable(){
    公共无效的run(){
        webView.pageDown(真正的);
    }
};
 

I have a WebView in Android which stores a conversation stream for my application.

Every 20 seconds the app polls a server for any messages and updates the WebView.

Each time the WebView updates it scrolls back to the top of the view.

I wanted to stop this happening so I tried using the webView.pageDown(true); but this always seems to be returning false.

Any help would be really appreciated. Here is the code:

    webView.loadDataWithBaseURL("fake://not/needed", html, "text/html", "utf-8", "");
    boolean scrolled = webView.pageDown(true);
    System.out.println("Scrolled is: " + scrolled);

解决方案

I had the same problem, so investigated further and found these releated here:

The only solution I manage to come up with is to create a handler that will delay the call for webView.pageDown(true) for 100ms, and then it works. It might need less or more time, probably dependent on the time the web view component needs to render the given html.

Here is the code for load and scroll:

webView.loadDataWithBaseURL("fake://not/needed", html, "text/html", "utf-8", "");
mWebViewScrollHandler.removeCallbacks(mScrollWebViewTask);
mWebViewScrollHandler.postDelayed(mScrollWebViewTask, 100);

Here is the code for the handler:

private final Handler mWebViewScrollHandler = new Handler();    

private final Runnable mScrollWebViewTask = new Runnable() {
    public void run() {
        webView.pageDown(true);
    }
};

这篇关于下页(真)总是返回虚假的WebView安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆