AppBarLayout 禁止滑动
来源:互联网 发布:php时间戳转换年月日 编辑:程序博客网 时间:2024/06/09 14:25
AppBarLayout 禁止滑动
有时候,有这样的需求,AppBarLayout是放在Activity中的,其中有几个Fragment需要AppBarLayout进行滑动,而另几个Fragment并不希望AppBarLayout进行滑动。
或者是CollapsingToolbarLayout布局其他的情况,也可以适用。
解决方法1
禁止AppBarLayout滑动
主要是在AppBarLayout的Behavior中,设置setDragCallback回调,将canDrag方法返回false,从而阻止滑动。
解决方法2
对于实现了NestedScrollingChild接口的View,通过继承,实现其NestedScrollingChild的方法实现,进行空实现,从而不触发Behavior事件。
比如Recyclerview,用这个Recyclerview来替代Recyclerview,即可不触发AppBarLayout的滑动。
/** * 可以控制NestedScrollingChild2接口的Recyclerview * * @author EthanCo * @since 2017/12/8 */public class NoNestedRecyclerView extends RecyclerView { boolean isNestedEnable = false; public NoNestedRecyclerView(Context context) { super(context); } public NoNestedRecyclerView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public NoNestedRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public boolean isNestedEnable() { return isNestedEnable; } public void setNestedEnable(boolean nestedEnable) { isNestedEnable = nestedEnable; } @Override public boolean startNestedScroll(int axes, int type) { if (isNestedEnable) { return super.startNestedScroll(axes, type); } else { return false; } } @Override public void stopNestedScroll(int type) { if (isNestedEnable) { super.stopNestedScroll(type); } } @Override public boolean hasNestedScrollingParent(int type) { if (isNestedEnable) { return super.hasNestedScrollingParent(type); } else { return false; } } @Override public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow, int type) { if (isNestedEnable) { return super.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow, type); } else { return false; } } @Override public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow, int type) { if (isNestedEnable) { return super.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow, type); } else { return false; } }}
阅读全文
0 0
- 禁止AppBarLayout滑动
- AppBarLayout 禁止滑动
- 4AppBarLayout滑动原理
- AppBarLayout滑动原理
- android 界面滑动隐藏(CoordinatorLayout+AppBarLayout)
- AppBarLayout、ViewPager、Fragment实现页面左右滑动
- 5CoordinatorLayout与AppBarLayout--嵌套滑动
- 解决AppBarLayout中的RecycleView的滑动冲突
- CoordinatorLayout + AppBarLayout实现滑动隐藏ToolBar
- appbarlayout+springview+viewpager滑动冲突的问题
- AppBarLayout
- AppBarLayout
- AppBarLayout
- 如何禁止GridView滑动
- viewpage禁止滑动--android
- ViewPager禁止滑动翻页
- UIScrollView 禁止向左滑动
- Listview禁止滑动
- 每天一道LeetCode-----计算两个序列最长的公共子序列长度
- 遍历list集合的方式
- Problem5:Longest Palindromic Substring
- linux CRONTAB定时任务
- Maven下载及配置本地仓库
- AppBarLayout 禁止滑动
- 关于枚举类型的学习(enum)
- QT控件大全 三十三 QRoundProgressBar
- 魏杰教授《解读十九大:迎接新时代,抓住新机遇》-转
- System.err: android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (c
- Linux系统下安装rz/sz命令及使用说明
- oracle,分区表归档
- C语言学习的第七天(续)
- salt_state