高效的WebView调整大小

时间:2018-12-03 11:17:38

标签: android android-webview android-toolbar android-scroll android-measure

我已经在我的应用中实现了浮动Toolbar(隐藏并向下滚动,向上显示),现在我看到WebView内部有一些闪烁的视图,确切地说,这些视图固定在底部。我注意到,由于WebView这样的偏移量更改,在调整Toolbar的大小时会发生这种情况:

appBarLayout.addOnOffsetChangedListener(this);

@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    boolean scrollFlagsSet = ((AppBarLayout.LayoutParams) getToolbar().getLayoutParams()).
            getScrollFlags() != 0;
    int bottom = (!scrollFlagsSet ? 0 : getToolbarHeightAttr()) + verticalOffset;
    swipeRefreshLayout.setPadding(0, 0, 0, bottom);
    swipeRefreshLayout.requestLayout();
}

swipeRefreshLayoutWebView的父母。方法会导致适当调整WebView的大小,并且效率很高,没有滞后(编辑:在较旧的设备上有点滞后)。但是,当WebView加载站点时,某些视图粘贴在底部,则在调整大小时这些视图会闪烁。我什至可以在WebView底边之间的间隙中看到文本(向下滚动时存在间隙,向上滚动时视图在底部被切掉)。我已经在屏幕上捕获了此行为(蓝色-Toolbar,灰色-WebView,浅蓝色和橙色-网络视图中的视图固定在底部)。看起来只需要几毫秒(一帧?),然后回到底部固定位置。该如何解决?

scrolling gap

在Chrome或Firefox中加载的同一页面运行正常,这些视图固定在底部并具有固定的位置,不会随着滚动/工具栏偏移量的变化而闪烁

我正在使用this NestedWebView。我的应用程序使用了很多加载到Activities中的片段,所有片段都扩展了我拥有BaseActivity的抽象CoordinatorLayoutWebViews属于碎片,放置在不同的容器中,没有选择将WebView直接放入CoordinatorLayout

编辑:XML

活动:

<androidx.coordinatorlayout.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main_cooridnator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <FrameLayout
        android:id="@+id/activity_main_content_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white" />

片段:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/fragment_webview_swipe_refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <my.package.widgets.web.NestedWebView
        android:id="@+id/fragment_webview_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbarStyle="outsideOverlay" />

0 个答案:

没有答案