如何使用片段在显示的图像中创建布局
这是图像屏幕截图:
我的问题是如何实现所示的堆栈布局?我已经搜索了资源文件,大多数只展示了如何实现两个片段。
有人可以给我一些如何创建如图所示的堆栈片段的示例吗?
会感激的。谢谢。
Here is the image screenshot:
My query is how can I implement the Stack layout shown? I have scoured the resource files and most only show how to implement two fragments.
Would anyone please give me any example of how I can create the Stack fragment as shown?
Will appreciate it. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的片段紧密相连,请不要在单独的活动中运行它们。对于单窗格情况,您只需在一个活动中切换片段即可。
否则,如果您确实想在活动之间将它们分开,则需要使用 onActivityResult() 模型来传播结果,并且在双窗格情况下,只需对第一个片段进行第二次调用 onActivityResult() 即可“模拟”它。请注意,Fragment.setTargetFragment() 包含一个请求代码参数来促进这一点。
恕我直言,片段不应加载其他片段。活动根据可用的屏幕空间加载片段。片段不应该知道也不关心当前活动中是否存在任何其他片段,或者其他活动中是否存在其他片段。
是的。
我什至不会让 F1 知道 F2 的存在,反之亦然。当用户在 F1 中执行的某些操作应导致主要上下文转换(例如,显示某些其他片段/活动)时,F1 应让托管活动知道,也许通过向 F1 注册的侦听器接口(以支持多个可能的托管活动) 。然后,该活动将安排 F2 出现在其自己的活动中或另一个活动中。类似地,当 F2 结束时,它会通过侦听器接口告知其托管活动,并且该活动可以将控制路由回适当的位置。
我对您的整个“F2 执行应导致其关闭的操作”方法有些怀疑,除非 F2 是 DialogFragment。
If your fragments are closely tied together, just don't run them in separate activities. For the single pane case you can just switch fragments within one activity.
Otherwise, if you do want to separate them between activities, you need to use the onActivityResult() model for propagating results back, and in the dual-pane case "emulate" it by just having the second call onActivityResult() of the first fragment. Note that Fragment.setTargetFragment() includes a request code argument to facilitate this.
IMHO, fragments should not load other fragments. Activities load fragments, based upon available screen space. Fragments should neither know nor care whether any other fragment exists in the current activity, or if other fragments are in other activities.
Yes.
I would not have F1 even know that F2 exists, or vice versa. When the user does something in F1 that should result in a major context shift (e.g., display some other fragment/activity), F1 should let the hosting activity know, perhaps via a listener interface registered with F1 (to support multiple possible hosting activities). The activity would then arrange for F2 to appear, either in its own activity or in another activity. Similarly, when F2 wraps up, it would let its hosting activity know via a listener interface, and that activity can route control back to the appropriate spot.
I am somewhat skeptical of your whole "F2 performs an action which should result in it being closed" approach, unless F2 is a DialogFragment.
下面给出了一种可能的解决方案
请根据使用情况调整宽度和高度
对于横向使用
对于纵向视图使用
One possible solution is given below
Please tweak width and heights according to the use case
For Landscape use
For Portrait view use