先给WebView
一个固定高度,在页面加载时重新设置高度
1 2 3 4 5 6
| <com.yooooex.widget.CustomWebView android:id="@+id/wv_custom" android:layout_width="match_parent" android:layout_height="200dp" android:layout_marginHorizontal="@dimen/d_10" android:scrollbars="none" />
|
1 2 3 4 5 6 7 8 9 10 11
| mWebView.setWebViewClient(new WebViewClient() { ... @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); ViewGroup.LayoutParams params = mWebView.getLayoutParams(); params.height = ViewGroup.LayoutParams.WRAP_CONTENT; mWebView.setLayoutParams(params); } ... }
|
你也可以先把 WebView
GONE 掉,在页面加载完毕时显示
1 2 3 4 5 6 7
| <com.yooooex.widget.CustomWebView android:id="@+id/wv_custom" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginHorizontal="@dimen/d_10" android:scrollbars="none" android:visibility="gone"/>
|
1 2 3 4 5 6 7 8 9
| mWebView.setWebViewClient(new WebViewClient() { ... @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); mWebView.setVisibility(View.VISIBLE); } ... }
|