英文:
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
来实现。您需要执行两个操作:
- 在您在
AndroidView
内充气的根视图中调用ViewCompat.setNestedScrollEnabled
。 - 将
nestedScroll
修改器应用于父级Scaffold
并提供您的NestedScrollConnection
。
您可以在文档页面A parent composable containing a child AndroidView中了解更多信息。
英文:
That should be possible using NestedScrollConnection
. You'll need to do two things:
- Call
ViewCompat.setNestedScrollEnabled
in the root View you are inflating withinAndroidView
- Apply the
nestedScroll
modifier to the parentScaffold
and provide yourNestedScrollConnection
You can read about this more in the documentation page A parent composable containing a child AndroidView.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论