android-CoordinatorLayout/NestedScrollView/隐藏显示工具栏/带有WebView的问题 [英] android - CoordinatorLayout/NestedScrollView/Hide-Show Toolbar/Issue with WebView

查看:110
本文介绍了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>

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

When I scrolls in the webview, the toolbar is hidden or shown (perfect !) but there is a problem with the loading / positioning web pages. For example, if I scrolls to the middle of a page and I click on a link, the new page that will load also be located at approximately the middle of the page instead of on top. As if scrollbars were not moving from one page to another.

如果我添加到NestedScrollView:

if I add to the NestedScrollView:

android:fillViewport="true"

一切都可以与webview一起使用(页面从顶部开始加载并显示得很好),但是我用工具栏:(

everything works with the webview (pages load and appear well although starting from the top) but I lose the Hide/Show with the toolbar :(

您对这个问题有任何想法吗?

Do you have any idea about this problem?

在此先感谢您的帮助:)

Thank you in advance for your help :)

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

(For information : Android Design Support Library : 23.0.1)

推荐答案

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

My assumption: Since you are putting the WebView inside a NestedScrollView the scrolling is not done on the WebView level so when you load a new page the NestedScrollView stays in the same position.

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

Suggestion: create a WebViewClient and override onPageStarted here you should change the NestedScrollView scroll position to 0:

nestedScrollView.scrollTo(0, 0);

这篇关于android-CoordinatorLayout/NestedScrollView/隐藏显示工具栏/带有WebView的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆