gpt4 book ai didi

Android Fragment onCreateView() 方法中的容器是什么

转载 作者:行者123 更新时间:2023-11-29 02:42:17 27 4
gpt4 key购买 nike

我想知道 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/

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