android – CoordinatorLayout / NestedScrollView /隐藏 – 显示工具栏/ WebView问题

我有一个问题:
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enteralways" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.nestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v4.widget.nestedScrollView>

</android.support.design.widget.CoordinatorLayout>

当我在网页视图中滚动时,工具栏被隐藏或显示(完美!),但是加载/定位网页有问题.
例如,如果我滚动到一个页面的中间,我点击一个链接,新的页面,将加载也位于大约中间的页面,而不是在顶部.好像滚动条没有从一个页面移动到另一个页面.

如果我添加nestedScrollView:

android:fillViewport="true"

一切都与webview一起工作(页面加载,看起来很好,虽然从顶部开始),但我失去了隐藏/显示与工具栏:(

你有什么想法吗?

预先感谢您的帮助 :)

(有关信息:Android设计支持库:23.0.1)

解决方法

我的假设:
由于您将WebView放置在nestedScrollView中,因此在WebView级别上不会执行滚动操作,因此当加载新页面时,nestedScrollView将保持在相同的位置.

建议:
创建一个WebViewClient并在此处覆盖onPageStarted,您应该将nestedScrollView滚动位置更改为0:

nestedScrollView.scrollTo(0,0);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...