【问题标题】:Can't zoom the webview under swipe to refresh无法在滑动刷新下缩放 webview
【发布时间】:2020-11-03 07:41:16
【问题描述】:

我在 swipetorefresh 布局下进行了 webview。我无法在 webview 中平滑缩放。但是,如果我删除 swipetorefresh 那么它会完美缩放。 这是布局:

<?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>

这是我实现缩放的代码。如果我们尝试缩放三四次,则缩放效果很差,但也不是很流畅。

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

【问题讨论】:

  • 您是否尝试过移除嵌套滚动视图并使webView 成为SwipeRefreshLayout 的直接子级?
  • @RezaBigdeli 也没有用。 :(

标签: android webview zooming swiperefreshlayout


【解决方案1】:

通过更改底层 Webview 的高度属性来解决这个问题。

对于 NestedScrollView 使用属性

android:fillViewport="true"

并用于 WebView android:layout_height="wrap_content"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多