R.layout的父母:怎么做?

时间:2021-09-04 20:55:43

how can an id be a parent of a layout folder?

id如何成为布局文件夹的父级?

in this code, it seems that R.id.layout_root is a parent of R.layout.custom_dialog, how can i do this in my folder tree?

在这段代码中,似乎R.id.layout_root是R.layout.custom_dialog的父级,我怎样才能在我的文件夹树中执行此操作?

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

Thanks

谢谢

1 个解决方案

#1


1  

I don't know if I understood well your question. Anyway, the inflate method that you are using simply inflates that custom_dialog layout as child of en existent VievGroup. You don't have to do anything in your folders, there is no relationships between that code and the directory hierarchy.

我不知道我是否理解你的问题。无论如何,您正在使用的inflate方法只是将该custom_dialog布局膨胀为现有VievGroup的子级。您不必在文件夹中执行任何操作,该代码与目录层次结构之间没有任何关系。

These are the 2 parameters that the method gets (from the doc):

这些是方法得到的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.

This small example maybe clarifies your doubts. This line of code:

这个小例子可能会澄清你的怀疑。这行代码:

LinearLayout lLayout = inflater.inflate(R.layout.buttons, R.id.layout1);

is equivalent to:

相当于:

Button b = (Button) inflater.inflate(R.layout.buttons, null);
LinearLayout lLayout = (LinearLayout)findViewById(R.id.layout1);
lLayout.addView(b);

#1


1  

I don't know if I understood well your question. Anyway, the inflate method that you are using simply inflates that custom_dialog layout as child of en existent VievGroup. You don't have to do anything in your folders, there is no relationships between that code and the directory hierarchy.

我不知道我是否理解你的问题。无论如何,您正在使用的inflate方法只是将该custom_dialog布局膨胀为现有VievGroup的子级。您不必在文件夹中执行任何操作,该代码与目录层次结构之间没有任何关系。

These are the 2 parameters that the method gets (from the doc):

这些是方法得到的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.

This small example maybe clarifies your doubts. This line of code:

这个小例子可能会澄清你的怀疑。这行代码:

LinearLayout lLayout = inflater.inflate(R.layout.buttons, R.id.layout1);

is equivalent to:

相当于:

Button b = (Button) inflater.inflate(R.layout.buttons, null);
LinearLayout lLayout = (LinearLayout)findViewById(R.id.layout1);
lLayout.addView(b);