如何使用Android Compose Scaffold AppBar CollapsedScrollBehavior与RecyclerView?

huangapple go评论62阅读模式
英文:

How to use Android Compose Scaffold AppBar CollapsedScrollBehavior with RecyclerView?

问题

我正在尝试实现折叠式appBar滚动行为(collapsedScrollBehavior),当内容在Compose中,比如LazyColumn中时,它运行得非常完美。

但在我的用例中,我正在使用Android Compose互操作API将RecyclerView放在Scaffold内容中的片段中。当我滚动片段中的RecyclerView时,Scaffold的appBar不会折叠/展开。

我知道这是一种特殊的情况,而且在Android Compose互操作API下找不到任何文档。请告诉我是否有任何方法可以尝试使其工作。

英文:

I am trying to implement the scaffold appBar collapsedScrollBehavior and it's working perfectly fine when the content is in compose like LazyColumn.

But in my use case, I am inflating the fragment with RecyclerView inside the Scaffold Content using Android Compose Interop APIs. Scaffold appBar is not collapsing/expanding when I am scrolling the RecyclerView which is inside the fragment.

I know it's a unique scenario and could found any documentation under Android Compose Interop APIs. Kindly let me know if there is anything I can try to make this work.

答案1

得分: 1

这可以使用 NestedScrollConnection 来实现。您需要执行两个操作:

  1. 在您在 AndroidView 内充气的根视图中调用 ViewCompat.setNestedScrollEnabled
  2. nestedScroll 修改器应用于父级 Scaffold 并提供您的 NestedScrollConnection

您可以在文档页面A parent composable containing a child AndroidView中了解更多信息。

英文:

That should be possible using NestedScrollConnection. You'll need to do two things:

  1. Call ViewCompat.setNestedScrollEnabled in the root View you are inflating within AndroidView
  2. Apply the nestedScroll modifier to the parent Scaffold and provide your NestedScrollConnection

You can read about this more in the documentation page A parent composable containing a child AndroidView.

huangapple
  • 本文由 发表于 2023年2月16日 06:47:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466138.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定