获取 webview 的最大滚动值 [英] Getting a maximum scroll value of a webview

查看:97
本文介绍了获取 webview 的最大滚动值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在 Scrollview 中您可以访问 scrollView.getMaxScrollAmount 但是我似乎不明白如何在 webview 上调用它.我试图作弊以获取有关它的信息.这是我尝试过的.

I know in Scrollview you can access scrollView.getMaxScrollAmount however I don't seem to understand how to call it on webview. I tried cheating to get the information about it. Here is what I tried.

该方法应该做的是它不断滚动特定数量并检查值是否没有增加该数量,它获取该数量并返回最大值.但是它不起作用.

What the method was suppose to do is that it continually scroll in a specific amount and checks if the value isn't increased in that amount it gets that amount and returns it with the max value. However it doesn't work.

public String scrollToMAX(){
        webView1.scrollTo(0, 0);
        Boolean istrue = true;
        String getIntData = "";
        int i = 0;
        while(istrue){
            int checker = webView1.getScrollY();
            if(i != checker){
                i = checker;
                getIntData = Integer.toString(i);
                istrue = false;
            }
            i=i+5000;
            webView1.scrollTo(0, i);
        }
        webView1.scrollTo(0, 0);
        return getIntData;
        //Put a return string here
    } 

推荐答案

给你:这对我来说很完美(滚动到最后)

here you go: this is working perfectly for me (it scrolls to the end)

诀窍在于使用函数 getContentHeight WebView

the trick is in using the function getContentHeight of WebView

package sherif.android.activity;

import sherif.android.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebClientTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        WebView webView = new WebView(this);
        String UserAgent = "User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; 
        //webView.getSettings().setUserAgentString(UserAgent); 
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://www.google.com/search?gcx=w&sourceid=chrome&ie=UTF-8&q=arsenal");
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
                Log.v("here","here");
                view.scrollBy(0, view.getContentHeight());
            }
        });
        setContentView(webView);
    }
}

这篇关于获取 webview 的最大滚动值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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