什么是调用从XML中的Andr​​oid窗口小部件时,正确的称呼?部件、正确、窗口、XML

2023-09-04 05:10:06 作者:王权浪女

我还是很新的机器人,但我试图跟上使用教程,YouTube上。围绕这句话一堆人扔膨胀XML。我开始用这句话为好,我感觉好像我不这样做是正确的。

I'm still very new to Android, but I am trying to keep up by using tutorials on YouTube. A bunch of people throw around the phrase "inflate the xml". I started to use this phrase as well, and I feel as though I'm not doing it right.

我唯一一次说吹大的XML是告诉别人的时候写的code使用小工具从Java中code中的XML。

The only time I say "inflate the xml" is when telling someone to write the code to use a widget from the xml in java code.

所以,如果我看到一个按钮上某人的布局, button01 的ID,我告诉他们膨胀的XML我预计按钮myButton的=(按钮)findViewById(R.id.button01);

So if I see a button on someones layout, with the id of button01, and I tell them to "inflate the xml" I expect Button mybutton = (Button) findViewById(R.id.button01);

这是我的错?

编辑: 它好像这是不正确的短语。做一件存在吗?

It seems as though this is not the correct phrase. Does one exist?

推荐答案

坐大的布局是指具有Android框架的过程中转换成XML格式的布局为对应于布局的不同意见的对象。

"Inflating" a layout refers to the process of having the Android framework convert a layout in XML format into objects corresponding to the different views in the layout.

膨胀你需要一个布局:

在一个XML格式的布局

a layout in XML format

RES /布局/ main.xml中

res/layout/main.xml

进入充气物体

LayoutInflater吹气=         (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

然后,您需要在布局上运行的通胀

You then need to run the inflation on the layout

   View view = inflator.inflate(R.layout.main)

之后,你可以使用访问的对象findViewById

After that you can access the objects using "findViewById"

    Button mybutton = (Button) view.findViewById(R.id.button01);

Activity类提供了一个辅助方法,既得到了充气机和充气布局

The Activity class provides a helper method which both gets the inflator and inflates the layout

    setContentView(R.layout.main)

在使用的setContentView的方法,该活动集被称之为findViewById时使用的默认视图

When using the "setContentView" method, the activity sets a default view which is used when calling "findViewById"