我發現你可以通過這三種方式膨脹佈局。但是不能在相應的語句中使用第二個和第三個參數。什麼是ViewGroup和attachedToroot參數?膨脹佈局方法和這些參數有什麼區別
一個活動以外首次使用:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.myNewInflatedLayout, ViewGroup);
View view = inflater.inflate(R.layout.myNewInflatedLayout, ViewGroup, attachedToroot);
Button myButton = (Button) view.findViewById(R.id.myButton);
這可能有助於:http://stackoverflow.com/questions/31854605/confusion-regarding-inflater-inflate-android-documentation –
@gauravjain我的問題不僅是第二部分,而且還有關於添加viewGroup或不添加。 – Kenji