聪明的android系统中使用的WebView如何显示HTML内容页? [英] How to Display the Html content page wise using webview in android?

查看:176
本文介绍了聪明的android系统中使用的WebView如何显示HTML内容页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我创建简单的应用程序中的WebView显示HTML网页,我使用的web视图,并显示在页面加载的时间是这样的。

hi i create simple app to display html page in webview i use the webview and display the page load time like this.

在此停用滚动,并使用下一个和previous按钮,前进和后退包含的内容。 所以,我的code是如下。

After this Disable the scroll and use the next and previous button to back and forward contain. So my code is below.

第一的onCreate显示添加web视图并加载HTML文件。

First onCreate display add webview and load the html file.

        mainWebView = (WebView) findViewById(R.id.mainWebView);
    mainWebView.setVerticalScrollBarEnabled(false);
    mainWebView.setHorizontalScrollBarEnabled(false);
    mainWebView.getSettings().setJavaScriptEnabled(true);
    mainWebView.setWebViewClient(new MyWebClient());
    mainWebView.setPictureListener(new MyPictureClass());

    mainWebView.loadUrl("file:///android_asset/chapter-001.html");

使用后MyWebclient班得到高度和宽度mainwebview。

class MyWebClient extends WebViewClient 
    {
        @Override
        public void onPageFinished(WebView view, String url) 
        {
            System.err.println("Page Finish Call");
            lanscapHeight = protraitHeight = findHeight = mainWebView.getHeight();
            System.err.println("Find     Height->"+findHeight);
            System.err.println("Portait  Height->"+protraitHeight);
            System.err.println("Landscap Height->"+lanscapHeight);


        }
    }

在此使用myPictureClass得到web视图包含长度。

after this use the myPictureClass to get the webView contain length.

class MyPictureClass implements PictureListener
    {
        @Override
        public void onNewPicture(WebView view, Picture picture) 
        {   

                proTraitContain = mainWebView.getContentHeight();

                System.err.println("picture Class Call-->"+proTraitContain);
        }
    }

下一步this.create按钮和previous后显示下一个和previous page.so使用SimpleOnGestureListener来检测触摸事件。

 btnNext = (Button) findViewById(R.id.btnNext);
        btnNext.setOnTouchListener(this);
        btnPrev = (Button) findViewById(R.id.btnPrev);
        btnPrev.setOnTouchListener(this);

覆盖触法。

 @Override
        public boolean onTouch(View view, MotionEvent event) 
        {
            if (view == btnNext)
            {
                btnClickFlage = true;
                gestureDetector.onTouchEvent(event);
            } else 
            {
                btnClickFlage = false;
                gestureDetector.onTouchEvent(event);
            }
            return false;
        }

implement the SimpleGestureListener class as Below.

class MyGesture extends SimpleOnGestureListener 
    {
        @Override
        public boolean onSingleTapUp(MotionEvent e)
        {

            super.onSingleTapUp(e);

                    System.err.println("Display Total Contain For Protrait -->"+proTraitContain);
                    System.err.println("Before Height-->" + findHeight);

                    if (btnClickFlage) 
                    {



                        if (findHeight > (proTraitContain+protraitHeight)) 
                        {
                            if(restProtraitFlag)
                            {
                                System.err.println("If part In side Flag-->"+findHeight);
                                findHeight=findHeight+protraitHeight;
                                restProtraitFlag=false;
                                //findHeight=findHeight+protraitHeight;
                                mainWebView.scrollTo(0, findHeight);
                                System.err.println("If part In side Flag-->"+findHeight);
                            }else
                            {
                                mainWebView.loadUrl("file:///android_asset/chapter-002.html");
                                restProtraitFlag=true;
                            }
                        } 
                        else
                        {
                            if(protraitFlag)
                            {
                                if(findHeight==protraitHeight)
                                {
                                    findHeight = protraitHeight;
                                }else
                                {
                                    findHeight = findHeight + protraitHeight;   
                                }
                                protraitFlag=false;
                            }else
                            {
                                findHeight = findHeight + protraitHeight;
                            }
                            mainWebView.scrollTo(0, findHeight);
                        }
                    }
                    else
                    {
                        restProtraitFlag=true;
                        if (findHeight<=0)
                        {
                            mainWebView.loadUrl("file:///android_asset/chapter-001.html");
                            System.err.println("Load Previous page");

                        } 
                        else 
                        {
                            findHeight = findHeight - protraitHeight;
                            mainWebView.scrollTo(0, findHeight);
                        }
                    }
                    System.err.println("After Height-->" + findHeight);
                }
            return true;
        }
    }

但我不能显示当前HTML页面的最后一页path.now什么do.any解决方案请give.it迫切。 我得到的内容宽度和正确使用scrollTo方法来显示,但我不能这样做it.after一些含有无法显示最后一页休息。

but i can't Display the last page of current html page path.now what to do.any solution please give.it's urgent. i get the content width properly and use the scrollTo method to display but i can't do it.after last page rest of some contain can't display.

请看到我的任何方式。

感谢提前..

推荐答案

朋友你好我终于得到了我的问题answer.i使用ScrollTo方法来滚动包含并显示下一个包含当前page.but问题是存在的web视图显示所有包含根据device.so所有的时间包含显示高于这个电流value.so我使用 Webview.getScale(); 的方法来显示比例由webview.according多少使用这个我用这个方法,并获取当前包含web视图中,并使用显示页面wise.it 终于到它的工作对我来说..

Hi Friends Finally i got my question answer.i use the ScrollTo method to scroll the contain and Display next contain of current page.but problem is there webView Display all contain according device.so all time contain display is higher then this current value.so i use the Webview.getScale(); method to Display how much scale use by webview.according to this i use this method and get current contain of webview in and use Display page wise.its finally its work for me..

名称为日历 Outhentication

这篇关于聪明的android系统中使用的WebView如何显示HTML内容页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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