简体   繁体   English

使用 Jetpack 导航组件在一个屏幕上显示多个片段

[英]Having multiple fragments at one screen with Jetpack Navigation component

Two fragments两个片段

I'm using navigation component and trying to understand is it possible to have two or more opened fragments simultaneously like mail app (one fragment is a list of mails, another fragment is detailed mail view).我正在使用导航组件并试图了解是否可以同时打开两个或多个片段,例如邮件应用程序(一个片段是邮件列表,另一个片段是详细的邮件视图)。 It's desirable to have them inside another container parent fragment.最好将它们放在另一个容器父片段中。

Yes, it's even recommended to design your app for multiple screen sizes .是的,甚至建议为 多种屏幕尺寸设计您的应用程序。 You can do so by creating alternative layouts , eg:您可以通过创建替代布局来做到这一点,例如:

res/layout/fragment_items.xml          # Screens smaller than 600dp available width
res/layout-w600dp/fragment_items.xml   # Screens 600dp wide and bigger

where layout-w600dp/fragment_items.xml includes both fragments .其中layout-w600dp/fragment_items.xml 包括两个片段 This way you keep the same navigation destination and don't need to complicate things with conditional navigation .这样您就可以保持相同的导航目的地,并且不需要使用条件导航使事情复杂化。

It's desirable to have them inside another container parent fragment.最好将它们放在另一个容器父片段中。

Depends.要看。 If you are going to use your list-fragment on multiple places, yes, because it would reduce duplicate code.如果你打算在多个地方使用你的列表片段,是的,因为它会减少重复的代码。 If not, or your list-fragment is going to be different on multiple screens (you might add or hide some buttons) you don't need the container;如果不是,或者您的列表片段在多个屏幕上会有所不同(您可能会添加或隐藏一些按钮),您就不需要容器; and can just modify the fragment_items.xml layout for different screen sizes.并且可以针对不同的屏幕尺寸修改fragment_items.xml布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 多个主机片段 - 导航 Android Jetpack - Multiple Host Fragments - Navigation Android Jetpack 具有多个活动的 JetPack 导航组件? - JetPack Navigation component with more than one activity? 在同一屏幕中具有多个片段的导航抽屉 - Navigation Drawer with multiple fragments in same screen 带有片段和 Jetpack 导航的底部导航行为 - Bottom Navigation Behaviour with fragments and Jetpack Navigation 底部导航的一个选项卡中有多个片段 - Multiple fragments in one tab of bottom navigation 如何防止在jetpack撰写导航中多次创建屏幕 - How to prevent multiple creation of a screen in jetpack compose navigation 使用 Android 导航组件在底部导航中的多个片段之间共享视图模型 - Share viewmodel between multiple fragments in Bottom Navigation with Android Navigation Component Jetpack 导航组件与 Jetpack Compose 兼容吗? - Jetpack Navigation Component with Jetpack Compose compatible? Android-一个活动选项卡屏幕的多个片段 - Android - One activity multiple fragments for tabs screen 如何在 Jetpack 导航中停止片段重新加载/重新创建 - How to stop fragments reloading/recreation in Jetpack navigation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM