这是什么意思夸大从XML文件的视图? [英] What does it mean to inflate a view from an xml file?

查看:121
本文介绍了这是什么意思夸大从XML文件的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  1. 获得 LayoutInflater
  2. 的实例
  3. 指定的XML膨胀
  4. 使用返回查看
  1. Get an instance of the LayoutInflater
  2. Specify the XML to inflate
  3. 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屋!

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