Android加載佈局的3種方式

在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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章