android - Android Fragment 中的膨胀布局
问题描述
在我的代码库中,我看到了两种在片段中扩展布局的方法,有什么区别?有最佳实践吗?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return View.inflate(getActivity(), R.layout.mylayout, null);
}
或者 :
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.mylayout, container, false);
}
解决方案
见来源View.inflate()
:
public static View inflate(Context context, int resource, ViewGroup root) {
LayoutInflater factory = LayoutInflater.from(context);
return factory.inflate(resource, root);
}
因此,在内部,class的inflate()
方法使用,这让我假设没有区别。View
LayoutInflater
推荐阅读
- ios13 - UIDatepicker VoiceOver 错误的accessibilityLabel
- python - 将数据发送到 Django 通道
- python - 如何混合使用 onehotencoding 和 bagofword
- c - 主题化容器 gtk+3 内的所有小部件
- visual-studio - 如何 Nuget 打包/转换多个 web.config 文件
- c - 计算C中char数组中的所有符号,而不是白色符号,所有单词和行
- google-chrome - Chrome 音频 API 未定义(Chrome 操作系统应用)
- json - 使用 IEnumerable
在 JSON 中 - android - 旋转 YUV420 android.media.Image Android
- angular - 没有获得多个复选框的复选框真值和假值,角度