簡體   English   中英

android - CoordinatorLayout / NestedScrollView /隱藏 - 顯示工具欄/ WebView問題

[英]android - CoordinatorLayout/NestedScrollView/Hide-Show Toolbar/Issue with 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>

當我在webview中滾動時,工具欄被隱藏或顯示(完美!)但是加載/定位網頁時出現問題。 例如,如果我滾動到頁面的中間並單擊鏈接,則將加載的新頁面也位於頁面的大約中間而不是頂部。 好像滾動條沒有從一個頁面移動到另一個頁面。

如果我添加到NestedScrollView:

android:fillViewport="true"

一切都適用於webview(頁面加載並顯示良好,雖然從頂部開始)但我丟失隱藏/顯示與工具欄:(

你對這個問題有什么看法嗎?

預先感謝您的幫助 :)

(有關信息:Android設計支持庫:23.0.1)

我的假設:由於您將WebView放在NestedScrollView ,因此在WebView級別上不會進行滾動,因此當您加載新頁面時, NestedScrollView保持在相同的位置。

建議:創建WebViewClient並覆蓋onPageStarted ,您應該將NestedScrollView滾動位置更改為0:

nestedScrollView.scrollTo(0, 0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM