gpt4 book ai didi

android - 将 fragment 添加到 fragment

转载 作者:行者123 更新时间:2023-11-29 23:17:18 37 4
gpt4 key购买 nike

我是 Android 开发的新手。我创建了一个 Fragment包含 View 、按钮、约束等,我称之为 fragment_code_activation_circles .现在我想将它添加到新 fragment 中,假设它是“主要”并包含我创建的所有其他 fragment ,我想为其设置约束,但我不知道如何添加它。我试图从普通托盘拖动 {}<fragment>在“设计”选项卡上进行筛选,但没有成功。这是可能的还是我可能做了一些我不应该做的事情?在 iOS 上,您可以简单地添加 View 的任何子项。类到父 View 并轻松设置约束。

最佳答案

您不能将 Activity 放入 Fragment 中 - Fragment 只能放置在 Activity 中。
您可以在 Activity 中放置任意数量的 Fragment,但不能将 Activity 放入 Fragment 中。将 fragment 视为可以放置在 Activity 内部的迷你 Activity 。

来自documentation:

You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).

现在,如果您想要 1 个包含 fragment 的屏幕,您将必须创建 1 个 Activity ,将 fragment 放入其中并在需要时随时替换它们。
要实现此行为,请使用新的 Navigation Architecture Component .

关于android - 将 fragment 添加到 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55108605/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com