遇到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);
}
}
<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" />
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弹窗
解决webview滑动底部会留白的问题
有问题欢迎讨论!