在Fragment/ListView/GridView/RecycleView种加载布局文件的方式总结:
//第一种加载View的方法 View view1 = LayoutInflater.from(context).inflate(R.layout.activity_main, null); //第二种加载View的方法 View view2 = View.inflate(context, R.layout.activity_main, null); //第三种加载View的方法 LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view3 = layoutInflater.inflate(R.layout.activity_main, null);
本文总结了在Fragment/ListView/GridView/RecyclerView中加载布局文件的三种方法:使用LayoutInflater.from(context)、View.inflate()以及getSystemService(Context.LAYOUT_INFLATER_SERVICE),为Android应用开发提供实用指南。

被折叠的 条评论
为什么被折叠?



