当前位置: 首页 > article >正文

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

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

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

运行效果入下

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

贴出 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>


http://www.kler.cn/a/280367.html

相关文章:

  • openlayers10+vue3+ts
  • 视创云展线上3D云展,在线自由创作!
  • 买小鹏M03别急,我来浇两盆冷水
  • echarts最新封装柱状图
  • ASP.NET Core 入门教学四 集成Redis
  • SpringBoot集成kafka开发-消息消费的分区策略(消费者如何判断从哪个分区中消费消息的?)
  • SQLi-LABS靶场36-40通过攻略
  • Flask+LayUI开发手记(三):LayUI表格的后端数据分页展现
  • Redis持久化RDB/AOF
  • Spring Boot 应用中注册和使用 Filter
  • 大数据技术之 Flume概述、安装(1)
  • xshell 终端选中文本后自动执行ctrl+c
  • 【机器学习】逻辑回归
  • 【React原理 - 任务调度之中断恢复】
  • 软件测试学习笔记丨Pytest配置文件
  • Leetcode 46. 全排列 排列型回溯 C++实现
  • JS WebSocket 深度解析
  • 8.22-docker的部署及其使用
  • Linux的log日志排查
  • 7-11 矩阵转置