安卓AppBarLayout与ViewPager2里的fragment里的webview滑动冲突

今天开发遇见一个头痛的问题,就是AppBarLayout和webview会存在一个冲突问题。如图下

问题出现在webview推到顶端的时候,AppBarLayout并不会跟着响应伸缩,解决办法是 在 webview 包 一个 父的 NestedScrollView 就能解决了。

运行效果入下

更改后的效果 就很丝滑,效果如上

贴出 xml 代码,仅限参考

XML 复制代码
<androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".view.ui.unittype.empireIntroduction.EmpireIntroductio2Activity">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="200dp">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:id="@+id/collapsing"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <ImageView
                    android:id="@+id/iv_image"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax" />

                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin">

                    <ImageView
                        android:id="@+id/imagebutton_finsh"
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:src="@drawable/ic_back_white"/>

                    <TextView
                        android:id="@+id/text_title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        tools:text="test"
                        android:textColor="@color/white"
                        android:textSize="18dp" />

                </androidx.appcompat.widget.Toolbar>

            </com.google.android.material.appbar.CollapsingToolbarLayout>

        </com.google.android.material.appbar.AppBarLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <com.google.android.material.tabs.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <androidx.viewpager2.widget.ViewPager2
                android:id="@+id/myViewPager"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </LinearLayout>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
相关推荐
FungLeo9 小时前
FengCMS · PHP+MySQL 升级实录 · 留言模块的六项问题:未审核进公开列表、旧回复覆盖、批量删除恢复
android·mysql·php·工程实践·fengcms
洞见前行10 小时前
Android 架构演进全解:从 MVC、MVP、MVVM 到 MVI 的原理、代码实战与得失权衡
android·架构·kotlin
专注Android黑科技12 小时前
Android 玩机黑科技:刀盾「系统冰点还原」与「保环境双清(恢复出厂不掉ROOT)」全图解教程
android·技术分享
StarsGreen13 小时前
Android meminfo 服务详细介绍
android
三少爷的鞋15 小时前
Main-safe、非阻塞与结构化并发,才是协程架构的核心
android
Escalating_xu1 天前
【MySQL】事务管理(上):从 ACID 到提交回滚,把一次转账真正做完整
android·数据库·mysql
StarsGreen1 天前
dumpsys gfxinfo数据信息分析方法
android
好的佩奇1 天前
蓝牙之 GATT 数据模型
android·flutter·蓝牙
Android小码家1 天前
Systemui和Launcher是如何无限重启
android·framework
GY-932 天前
【Android】WorkManager
android