android - How to Trigger a Scroll Behavior on a Toolbar inside a CoordinatorLayout
问题描述
I have a [PDFView][1]
as the direct child of a CoordinatorLayout
as in:
I tried to add app:layout_behavior="@string/appbar_scrolling_view_behavior"
to the PDFView
but it's not compatible so it isn't triggering any scroll behavior on the Toolbar
.
The Toolbar
has app:layout_scrollFlags="scroll|enterAlways|snap"
and I know it works because I already tested it with a NestedScrollView
instead of the PDFView
.
So I want to achieve this programatically, but I can't find any documentation on how to let the CoordinatorLayout
know there's a scroll going on and it should animate the Toolbar
going away.
How can I trigger this behavior programatically? The PDFView
has a ScrollListner
I just don't know how to connect it to the CoordinatorLayout
.
解决方案
首先,PDF 视图没有实现 NestedScrollingChild2 ,因此您需要实现它。实现它之后,你必须实现五个 方法。还要创建一个实例NestedScrollingChildHelper并将实现的方法委托给该实例。
视图子类应在构造时将此类的最终实例实例化为字段。对于在此类中具有匹配方法签名的每个 View 方法,将操作委托给重写方法实现中的帮助程序实例。这实现了嵌套滚动的标准框架策略。
让我知道它是否有效。
推荐阅读
- python - 为什么 POST 看不到 GET 中设置的属性
- .net - Visual Studio 灰色文本背景,如何去除?
- c# - 如何使用 .NET Core 身份框架在 .NET Core MVC 前端对用户进行身份验证
- python - 如何在 Python scikit-learn 中更改 RandomForestClassifier
- java - Java中的Oracle查询
- kotlin - Kotlin 的 'let' 加上 elvis,以及意外的 null 返回值
- php - 多对多关系中的 Laravel 查询构建器
- java - 在 Maven 多模块项目中按层或功能打包结构?
- pandas - pandas中的多列计算
- r - R 是否有一个类似字符串的对象来公开文件 API?