[英]Having multiple fragments at one screen with Jetpack Navigation component
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.