• android 解决webView底部留白问题


    前言

    遇到webview滑动的时候,底部留白严重,一直滑不到底!
    经过测试,以下方法可以尝试

    自定义WebView

    public class CustomNestedScrollWebView extends WebView {
    
    
        public CustomNestedScrollWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
        }
    
        public CustomNestedScrollWebView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        public CustomNestedScrollWebView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public CustomNestedScrollWebView(Context context) {
            super(context);
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            //根据手机屏幕重新计算高度
            int mExpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, mExpandSpec);
        }
    
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    使用方法

      <xxx.CustomNestedScrollWebView
                        android:id="@+id/webView_form1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="fill_vertical"
                        android:clipChildren="false"
                        android:clipToPadding="false"
                        android:fadingEdge="none"
                        android:fillViewport="true"
                        android:longClickable="false"
                        android:nestedScrollingEnabled="false"
                        android:overScrollMode="never"
                        android:scrollbars="none" />
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    基本配置

    		WebSettings webSetting = webView_form.getSettings();
     		webSetting.setJavaScriptEnabled(true);//支持js
            webSetting.setAllowFileAccess(true);
            webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
            webSetting.setSupportZoom(true);
            webSetting.setTextZoom(100);
            webSetting.setBuiltInZoomControls(true);
            webSetting.setUseWideViewPort(true);
            webSetting.setSupportMultipleWindows(false);
            webSetting.setAppCacheEnabled(true);
            webSetting.setDomStorageEnabled(true);
            webSetting.setGeolocationEnabled(true);
            webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
            webSetting.setAppCachePath(getDir("appcache", 0).getPath());
            webSetting.setDatabasePath(getDir("databases", 0).getPath());
            webSetting.setGeolocationDatabasePath(getDir("geolocation", 0)
                    .getPath());
            webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
            webSetting.setJavaScriptCanOpenWindowsAutomatically(true); //允许js弹窗
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    测试

    解决webview滑动底部会留白的问题
    有问题欢迎讨论!

  • 相关阅读:
    接口的用法、常量接口、微观接口和宏观接口(JAVA基础六)
    python学习笔记:第九章异常
    力扣(LeetCode)32. 最长有效括号(C++)
    使用cpolar内网穿透实现远程Stackedit Markdown编辑器
    android 12.0 去掉未知来源弹窗 默认授予安装未知来源权限
    HarmonyOS开发探索:自定义键盘-webview
    dom xss->半自动化
    亚马逊API接口
    【路径规划-VRP问题】基于混合K-Means和蚁群算法求解带容量车辆路径规划CVRP问题附matlab代码
    巧用 background-clip 实现超强的文字动效
  • 原文地址:https://blog.csdn.net/Life_s/article/details/138151892