Android WebView cannot get height above version 4.4

Source: Internet
Author: User

In systems below 4.4, we usually listen to the webview slide to the end of the method as follows:


1, first re-webview,foundwebview

public class Foundwebview extends WebView {scrollinterface MT;        Public Foundwebview (Context context) {super (context);        TODO auto-generated Constructor stub} public Foundwebview (context context, AttributeSet attrs, int defstyle) {    Super (context, attrs, Defstyle);        } public Foundwebview (context context, AttributeSet Attrs) {Super (context, attrs); TODO auto-generated Constructor stub} @Override protected void onscrollchanged (int l, int t, int oldl, int ol        DT) {super.onscrollchanged (L, T, OLDL, Oldt);        LOG.E ("Hhah", "+l+" "+t+" "+oldl+" "+oldt");    Mt.onschanged (L, T, OLDL, Oldt);    } public void Setoncustomscroolchangelistener (Scrollinterface t) {this.mt=t;  }/** * Defines the sliding interface * @param t */public interface Scrollinterface {public void onschanged (int l,    int t, int oldl, int oldt); }    }


2, very few people do not customize the WebView bar, directly call the system always have a address bar too much pain, so it is generally in an activity to load WebView

Mwebview.setoncustomscroolchangelistener (New Scrollinterface () {            @Override public            void onschanged (int l, int T, int oldl, int Oldt) {                //TODO auto-generated method stub                webviewhight = Mwebview.getcontentheight () *mwebview.g Etscale ();                Already at the bottom                if ((int) Webviewhight = = (Mwebview.getheight () + mwebview.getscrolly ())) {                                                    }                //is already at the top//                if ( Mwebview.getscaley () = = 0) {////                }}        );


3, at the bottom and the top can be operated, but in 4.4 of the system, I found that regardless of the height obtained will be like this

(int) webviewhight > mwebview.getheight () + mwebview.getscrolly ()

On a test phone found that the difference is always 1, no other phone test


4, currently cannot be solved, but considering the bottom display, I have directly made an offset here,

  Mwebview.setoncustomscroolchangelistener (New Scrollinterface () {            @Override public            void onschanged (int l, int T, int oldl, int Oldt) {                //TODO auto-generated method stub                webviewhight = Mwebview.getcontentheight () *mwebview.g Etscale ();                To resolve 4.4 The system cannot get the correct height plus a "<10"                if ((int) webviewhight-(Mwebview.getheight () + mwebview.getscrolly ()) < 10) {                      //already at bottom 10 offset                                    }                Already at the top//                if (mwebview.getscaley () = = 0) {////}}}        );


This can also solve the 4.4 system you operate at the bottom (actually not completely at the bottom)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.