一、xml佈局中,webview設置一个高度
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:scrollbars="none" />
</androidx.core.widget.NestedScrollView>
二、在onPageFinished中重新给webview设置宽和高
webView.setOnPageFinishListener(() -> {
runOnUiThread(new Runnable() {
@Override
public void run() {
webView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
}
});
网友评论