- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道 onCreateView()
中的容器参数是什么,因为当我将 View 膨胀到那个容器时,我想知道这是什么 viewGroup,它是我们将添加的 Activity 的 viewGroup fragment 到?如果它是真的那么为什么我们需要将它附加到 inflate 方法中,因为我认为我们无论如何都会将这个 fragment 添加到 Activity 的 xml 中的 Activity View 组中。
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_top,container,true);
return view;
}
最佳答案
The
inflate()
method takes three arguments:
The
resource ID
of the layout you want to inflate.The
ViewGroup
to be the parent of the inflated layout. Passing the container is important in order for the system to apply layout parameters to the root view of the inflated layout, specified by the parent view in which it's going.- A
boolean
indicating whether the inflated layout should be attached to the ViewGroup (the second parameter) during inflation.
有关更多信息,请参阅 here
关于Android Fragment onCreateView() 方法中的容器是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43281924/
我已经搜索了与此相关的每个主题,但没有一个对我有帮助...我是初学者,非常感谢您的回答...当我启动该应用程序时,一切都很好,但是当我第二次调用 HomeFragment 时,出现了问题。我试过了 F
我尝试将 Android 兼容性库(或现在称为支持库)v4 用于 pre-honeycomb android 设备。我明白,我应该使用 FragmentActivity 类,而不是使用 Fragmen
我正在创建一个选项卡式应用程序,但遇到了问题。当我单击我所在位置旁边的选项卡时,onCreateView() 运行。我的意思是,如果我有三个选项卡(设置、 map 和电机),如果我单击电机选项卡, m
我的选项卡有一个viewpager。我有三个选项卡,我在第一个选项卡中进行计算,将其存储在仍然是共享首选项的tinyDb 中。我还在第二个选项卡中进行了另一个计算,并将答案存储在tinydb中,然后通
我有一个带有 Activity 和 3 个可滑动选项卡( fragment )的应用程序。我在选项卡内创建了一些大量创建的 UI 元素,这些元素需要一些时间才能创建,第一次运行没问题,但每次我滑动它们
我不止一次看到这个问题在这里被问到,但我不知道如何解决我的问题。 我有一个用户执行此操作的应用: 1 - 打开 navigationDrawer 并选择一个选项(创建了一个 fragment )(我在
我创建了一个具有以下构造函数的自定义首选项 public CoordinatesPreference(Context context, AttributeSet attrs) { super(
我正在尝试构建一个包含多个 fragment 的应用程序,其中所有 fragment 都实现了 LoaderCallbacks。我一直在阅读 StackOverflow 上的帖子,其中大多数都指出要使
当我将 onCreateView() 中的 container 类型从 Viewgroup? 更改为 Viewgroup 时,我得到了这个错误: 这是为什么? 最佳答案 您收到错误,因为 ViewGr
我试图将 TimePicker 片段放入我创建的选项卡类中,但以下重写方法导致了问题: @Override public View onCreateView(LayoutInflater in
我遇到了一个奇怪的问题,onCreateView每次我导航到 TabLayout 中的相邻选项卡时都会被调用。这是我的代码: news_feed.java: private static TabLay
如果我有在片段的 onCreateView 中声明的变量;有没有办法可以从 onCreateView 外部访问这些变量? public View onCreateView(LayoutInflate
我当前的问题是我正在尝试触发 Animator 在两个 Activity 之间转换。我的目标是创建从一个 Activity 到另一个 Activity 的循环显示过渡。 我开始收到此错误:“无法在分离
我正在将数据从 Activity 发送到 fragment 并使用以下代码启动 fragment : if (conversation != null) { FragmentManager f
这里我写了一个简单的 Activity 和 fragment 。我改变了方向,因为它是 configuration change 调用,所以它再次调用了 Activity.onCreate() 但为什
我注意到我的一个 fragment 的 onCreateView() 从未被调用,我不知道为什么。我需要能够在 onResume() 中进行更改,但是那也从未被调用。 这是我添加 fragment 的
我正试图摆脱一个麻烦的异常。 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedIn
尝试将 RecyclerView 实现到我的应用程序中,我不明白为什么我会收到“未连接适配器;跳过布局”我想我清楚地在 onCreateView 中设置了它。其他一些帖子建议将其移至 Oncreate
我想知道 onCreateView() 中的容器参数是什么,因为当我将 View 膨胀到那个容器时,我想知道这是什么 viewGroup,它是我们将添加的 Activity 的 viewGroup f
我创建了一个应用程序,它使用了 antonyt 的 InfiniteViewpager。 我想在创建 View 时在 Imageview 上添加动画,但我的动画工作了几次,但并非总是如此。这是代码:
我是一名优秀的程序员,十分优秀!