什么是调用从XML中的Andr​​oid窗口小部件时,正确的称呼? [英] What is the correct term when calling a widget from xml in Android?

查看:211
本文介绍了什么是调用从XML中的Andr​​oid窗口小部件时,正确的称呼?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还是很新的机器人,但我试图跟上使用教程,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"

这篇关于什么是调用从XML中的Andr​​oid窗口小部件时,正确的称呼?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆