想要禁止CoordinatorLayout中滚动AppBarLayout,需要怎么做?
导读:相信很多人对想要禁止CoordinatorLayout中滚动AppBarLayout,需要怎么做都不太了解,下面小编为你详细解释一下这个问题,希望对你有一定的帮助 我有AppBarLayout中具有视差效果的MapFragment,我想...
相信很多人对想要禁止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的问题,欢迎关注网络或到官网咨询客服。声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 想要禁止CoordinatorLayout中滚动AppBarLayout,需要怎么做?
本文地址: https://pptw.com/jishu/655003.html
