我是新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