您现在的位置是:群英 > 开发技术 > 编程语言
想要禁止CoordinatorLayout中滚动AppBarLayout,需要怎么做?
Admin发表于 2022-04-12 15:33:291753 次浏览
相信很多人对想要禁止CoordinatorLayout中滚动AppBarLayout,需要怎么做都不太了解,下面群英小编为你详细解释一下这个问题,希望对你有一定的帮助

我有AppBarLayout中具有视差效果的MapFragment,我想在AppBarLayout上禁用滚动,因为不可能在地图上移动,因为地图上的触摸偶数总是作为滚动事件处理.

我想通过仅滚动RecyclerView(位于屏幕底部)来处理AppBarLayout的折叠。


xml代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@ id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/public_white"
    android:fitsSystemWindows="false">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@ id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/public_white"
        app:elevation="0dp">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@ id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/public_background"
            android:paddingBottom="@dimen/public_dim20"
            app:contentScrim="#000000"
            app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
            app:titleEnabled="false">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/public_white"
                android:orientation="vertical">

                <RelativeLayout
                    android:id="@ id/player_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <!--<View-->
                    <!--    android:id="@ id/video_player"-->
                    <!--    android:layout_width="match_parent"-->
                    <!--    android:layout_height="@dimen/public_height_210dp" />-->

                    <com.aliyun.player.alivcplayerexpand.widget.AliyunVodPlayerView
                        android:id="@ id/video_player"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/public_dim420" />

                    <!--<RelativeLayout-->
                    <!--    android:id="@ id/back_layout"-->
                    <!--    android:layout_width="wrap_content"-->
                    <!--    android:layout_height="@dimen/public_height_50dp"-->
                    <!--    android:gravity="left">-->

                    <!--    <ImageView-->
                    <!--        android:layout_width="wrap_content"-->
                    <!--        android:layout_height="wrap_content"-->
                    <!--        android:layout_centerVertical="true"-->
                    <!--        android:layout_marginLeft="@dimen/public_margin_10dp"-->
                    <!--        android:layout_marginRight="@dimen/public_margin_10dp"-->
                    <!--        android:src="@mipmap/public_ic_arrow_back_white_24dp" />-->

                    <!--</RelativeLayout>-->

                </RelativeLayout>

                <TextView
                    android:id="@ id/tv_coure_name_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="@dimen/public_dim32"
                    android:textColor="@color/public_main_text_color" />

                <TextView
                    android:id="@ id/tv_introduction_name_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingStart="@dimen/public_dim32"
                    android:paddingEnd="@dimen/public_dim32"
                    android:paddingBottom="@dimen/public_dim32"
                    android:textColor="@color/public_main_text_color" />

            </LinearLayout>

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:orientation="vertical"
            app:layout_collapseMode="pin"
            app:layout_scrollFlags="exitUntilCollapsed|enterAlways|enterAlwaysCollapsed">

            <net.lucode.hackware.magicindicator.MagicIndicator
                android:id="@ id/magic_indicator"
                android:layout_width="match_parent"
                android:layout_height="@dimen/public_dim100" />

        </LinearLayout>

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

    <androidx.viewpager.widget.ViewPager
        android:id="@ id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/public_white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>


DragCallback界面允许选择是否通过滚动到AppBarLayout来控制兄弟滚动视图,您可以通过调用来定义一个:

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
    @Override
    public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
        return false;
    }
});


通常总是返回false,您的滚动视图将不再被ABL控制,注意:在调用它之前,应该检查ViewCompat.isLaidOut(appBarLayout),否则params.getBehavior()将返回null,

通过以上内容的阐述,相信大家对想要禁止CoordinatorLayout中滚动AppBarLayout,需要怎么做已经有了进一步的了解,更多appbarlayout的问题,欢迎关注群英网络或到群英官网咨询客服。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。

相关信息推荐
2022-09-24 17:13:18 
摘要:6.0中间件分为系统中间件和应用中间件,本文就详细的介绍一下Thinkphp6.0中间件的具体使用,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
2021-11-20 17:46:03 
摘要:python中有多种类型的括号,例如小括号、中括号、大括号和花括号,那么这些括号都表示什么,怎样使用呢?这篇文章我们来了解一下python中的括号,感谢的朋友接下来就跟随小编来一起学习一下吧!
2022-02-15 17:52:25 
摘要:如何利用C语言编写简易的猜数游戏?用C语言实现猜数游戏是一个比较基础的,适合新手学习的一个示例,中文示例代码有一定的参考价值,新手朋友可以参考了解看看,希望对学习C语言的应用有帮助。
云活动
推荐内容
热门关键词
热门信息
群英网络助力开启安全的云计算之旅
立即注册,领取新人大礼包
  • 联系我们
  • 24小时售后:4006784567
  • 24小时TEL :0668-2555666
  • 售前咨询TEL:400-678-4567

  • 官方微信

    官方微信
Copyright  ©  QY  Network  Company  Ltd. All  Rights  Reserved. 2003-2019  群英网络  版权所有   茂名市群英网络有限公司
增值电信经营许可证 : B1.B2-20140078   粤ICP备09006778号
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 或 0668-2555555
微信公众号
返回顶部
返回顶部 返回顶部