最近写一个项目,用WebView加载网页的时候有时能显示全,有时能,有事还得滑动一下才能显示出来,奇怪,代码都是从一个正常的项目中拷贝过来的,怎么会出问题呢,而且百度谷歌半天都没解决,经过半天的排查,原因如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"//问题就出在这
android:layout_height="match_parent"
tools:context="com.internationaltanke.common.base.TkWebActivity">
<com.international.tanke.common.widget.TKWebView
android:id="@+id/cwv_cashou"
android:layout_width="match_parent"
android:layerType="software"
android:layout_height="match_parent"/>
</LinearLayout>
问题是
android:orientation="vertical"忘了指定了,这个不是有默认值吗?为啥不指定会导致WebView出问题呢,哪个大神解释一下。
这个问题解决了以后,发现一个网页图片加载不出来,必须滑动一下才能加载出来,至今都没找到解决方案,只能在Activity中加入下面的代码:
scrollBy(0,100);
scrollBy(0,100);
让网页滑动一下临时解决,哪位大神有解决方案提供一下,非常感激。