2011-12-18 55 views
0

id如何成爲佈局文件夾的父項?R.layout的R.id父母:如何做到這一點?

在這段代碼中,似乎R.id.layout_rootR.layout.custom_dialog的父親,我怎麼能在我的文件夾樹中做到這一點?

View layout = inflater.inflate(R.layout.custom_dialog, 
       (ViewGroup) findViewById(R.id.layout_root)); 

感謝

+0

我不明白的問題你的答案 – Entreco 2011-12-18 23:43:29

回答

1

我不知道如果我深知你的問題。無論如何,您正在使用的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); 
+0

ARF好感謝,這是這麼簡單......感謝您的快速回答! – Paul 2011-12-20 02:32:54

+0

沒問題@保羅!很高興幫助! – gwa 2011-12-20 02:40:07

+0

編輯:哼哼,實際上:爲什麼我們要膨脹R.layout.buttons,而我們不會爲lLayout做? (這似乎使用setContentView而不是權利?) – Paul 2011-12-20 02:41:46