无法在滑动下缩放

无法在滑动下缩放

本文介绍了无法在滑动下缩放 webview 以刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 swipetorefresh 布局下有 webview.我无法在 web 视图中平滑缩放.但是,如果我删除 swipetorefresh,那么它就会完美地缩放.这是布局:

I've webview under swipetorefresh layout. I cannot zoom smoothly in the webview. But, if I remove the swipetorefresh then it is zooming perfectly.This the layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:ignore="MergeRootFrame"
    android:keepScreenOn="true">

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipeContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical">
        <WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/webView"
            android:scrollbars="vertical"
            />
        </androidx.core.widget.NestedScrollView>
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>

这是我实现缩放的代码.试了三四四次就勉强变焦了,而且也不流畅.

and this the code that I implemented to zoom. It is bearely zooming if we try three four times to zoom but that is also not smooth.

WebSettings settings = this.webView.getSettings();
        settings.setBuiltInZoomControls(true);
        settings.setSupportZoom(true);
        settings.setDisplayZoomControls(false);

推荐答案

让这个解决方案改变了底层 Webview 的高度属性.

Got this one working with changing the height attribute of the underlying Webview.

对于 NestedScrollView 使用属性

For NestedScrollView use attribute

android:fillViewport="true"

和 WebView 使用android:layout_height="wrap_content"

and for WebView useandroid:layout_height="wrap_content"

这篇关于无法在滑动下缩放 webview 以刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 19:53