这是什么意思夸大从XML文件的视图? [英] What does it mean to inflate a view from an xml file?
问题描述
我是新android开发,并保持整个引用来充气从布局xml文件的意见。我用Google搜索和搜索的开发指南,但仍然没有能够拿起一个意义是什么意思。如果有人可以提供一个非常简单的例子,它会是多少AP preciated。
I am new to android development and keep coming across references to Inflating views from a layout xml file. I googled and searched the development guide but still wasn't able to pick up a sense for what it means. If someone could provide a very simple example, it'd be much appreciated.
推荐答案
当你写了一个XML布局,这将是充气的由Android操作系统这基本上意味着它会被渲染。让我们调用的隐性通胀的(操作系统将膨胀认为你)。例如:
When you write an XML layout, it will be inflated by the Android OS which basically means that it will be rendered. Let's call that implicit inflation (the OS will inflate the view for you). For instance:
class Name extends Activity{
public void onCreate(){
// the OS will inflate the your_layout.xml
// file and use it for this activity
setContentView(R.layout.your_layout);
}
}
您也可以明确使用 LayoutInflater
膨胀的看法。在这种情况下,你必须:
You can also inflate views explicitly by using the LayoutInflater
. In that case you have to:
- 获得
LayoutInflater
的实例
- 指定的XML膨胀
- 使用返回
查看
- Get an instance of the
LayoutInflater
- Specify the XML to inflate
- Use the returned
View
例如:
LayoutInflater inflater = LayoutInflater.from(YourActivity.this); // 1
View theInflatedView = inflater.inflate(R.layout.your_layout, null); // 2 and 3
这篇关于这是什么意思夸大从XML文件的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!