Android WebView Versions later than 4.4 cannot obtain the height

Source: Internet
Author: User

In systems lower than 4.4, we usually listen to the webview sliding end as follows:


1. Repeat webview and 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 oldt) {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. Few people do not customize webview. It is too painful to directly call the system to load webview in an activity.

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. getScale (); // if (int) webviewHight = (mWebView. getHeight () + mWebView. getScrollY () {} // It is already at the top. // if (mWebView. getScaleY () = 0 ){////}}});


3. the operation can be performed at the bottom and top, but in the 4.4 system, I found that the height obtained in any way would be like this.

(int)webviewHight > mWebView.getHeight() + mWebView.getScrollY()

I found that the difference is always 1 on one mobile phone, but not on other mobile phones.


4. It cannot be solved at present, but considering the display at the bottom, I made an offset directly 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. getScale (); // Add a "<10" if (int) webviewHight-(mWebView. getHeight () + mWebView. getScrollY () <10) {// It is already at the bottom 10 offset} // It is already at the top // if (mWebView. getScaleY () = 0 ){////}}});


This can also solve the problem where you operate the 4.4 system at the bottom (in fact, it is not entirely at the bottom)


Related Article

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.