NestedScrollView嵌套WebView,Android8.0以上不显示或者显示空白问题记录

NestedScrollView嵌套WebView,Android8.0以上不显示或者显示空白问题记录

最近开发页面用到NestedScrollView嵌套WebView,别的页面也在用,可以正常显示,我自己的页面,在vivo上可以显示,华为和小米的高版本(Android8.0以上)上就显示不出来,代码很简单如下:

 <android.support.v4.widget.NestedScrollView
   <RelativeLayout
    <WebView
          android:id="@+id/webview"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
     />
    </RelativeLayout>
 </android.support.v4.widget.NestedScrollView>

于是乎上网一搜,千篇一律的是webview加载完成以后重新计算webview的高度,但是对于我来说,还是不行。于是乎,我对比了别的页面和我的页面的区别,发现唯一的区别是WebView的父布局是线性布局,如下:

 <android.support.v4.widget.NestedScrollView
   <LinearLayout
    <WebView
          android:id="@+id/webview"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
     />
    </LinearLayout>
 </android.support.v4.widget.NestedScrollView>

果然,可以显示了,从结果来看,NestedScrollView嵌套WebView的时候,WebView父布局必须是LinearLayout,不然显示有问题。
如果还不行,在webview设置完成后,立即加载空白,如下:

webview.loadUrl("about:blank");

至此,就都可以了。
特此记录一下.。

**

最新发现,根本原因是:html里面的img图片,没有设置高度和显示的方式,设置了的话,客户端不要处理也可以。

**

猜你喜欢

转载自blog.csdn.net/gemgaozhen/article/details/106235398