id如何成爲佈局文件夾的父項?R.layout的R.id父母:如何做到這一點?
在這段代碼中,似乎R.id.layout_root
是R.layout.custom_dialog
的父親,我怎麼能在我的文件夾樹中做到這一點?
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
感謝
id如何成爲佈局文件夾的父項?R.layout的R.id父母:如何做到這一點?
在這段代碼中,似乎R.id.layout_root
是R.layout.custom_dialog
的父親,我怎麼能在我的文件夾樹中做到這一點?
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
感謝
我不知道如果我深知你的問題。無論如何,您正在使用的inflate方法只是將custom_dialog佈局誇大爲存在VievGroup的子項。您不必在文件夾中執行任何操作,該代碼與目錄層次結構之間不存在任何關係。
這些是2個參數的方法獲取(從DOC):
resource ID for an XML layout resource to load (e.g., R.layout.main_page)
root Optional view to be the parent of the generated hierarchy.
這個小例子,也許你澄清疑慮。這行代碼:
LinearLayout lLayout = inflater.inflate(R.layout.buttons, R.id.layout1);
等同於:
Button b = (Button) inflater.inflate(R.layout.buttons, null);
LinearLayout lLayout = (LinearLayout)findViewById(R.id.layout1);
lLayout.addView(b);
我不明白的問題你的答案 – Entreco 2011-12-18 23:43:29