在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);