对于混乱的Andr​​oid inflater.inflate文档 [英] Confusion regarding inflater.inflate Android documentation

查看:173
本文介绍了对于混乱的Andr​​oid inflater.inflate文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这个链接学习片段: http://developer.android.com /guide/components/fragments.html

I'm studying fragments from this link : http://developer.android.com/guide/components/fragments.html

有是给出一张code的:

There's a piece of code given as:

public static class ExampleFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.example_fragment, container, false);
}

}

我困惑的attachToRoot参数,以便我抬头对堆栈溢出一些帮助,发现类似的问题很好的答案。所以,我的理解是,如果你把它设置为true,该片段被连接到活动的根布局,并从那里获得它的LayoutParams。如果是假的,将只是返回虚增布局的根源,就像一个片段一个独立的视图(派生从容器中通过布局PARAMS)。

I was confused about the attachToRoot parameter so I looked up on Stack Overflow for some help and found good answers on similar problem. So what I understand is if you set it to true, the fragment gets attached to the activity's root layout, and derives its layoutparams from there. If it's false it would simply return the root of the inflated layout and acts like a standalone view for a fragment (deriving the layout params from the passed in container).

现在我读进一步下跌的文档中关于attachToRoot为上面的例子:

Now I read further down in the documentation regarding attachToRoot for the above example:

一个布尔值,指示是否虚增布局应附
  充气期间的ViewGroup(第二个参数)。 (在这种情况下,
  这是假的,因为系统已经插入充气
  布局倒入容器中传递真正将创建一个冗余的看法
  组中的最终布局。)

A boolean indicating whether the inflated layout should be attached to the ViewGroup (the second parameter) during inflation. (In this case, this is false because the system is already inserting the inflated layout into the container—passing true would create a redundant view group in the final layout.)

,它说,它应该是假的,因为我们已经插入布局放入容器中我没有得到最后的括号声明。是什么意思,我们正在已经插入容器没有attachToRoot为真?如果该参数是真的,怎么会最终布局有多余的视图组。阐述这一部分的一个例子是一个很大的帮助。谢谢。

I don't get the last parenthesis statement where it says that it should be false because we're already inserting the layout into the container. What does it mean that we're already inserting into the container without attachToRoot as true? If the parameter is true, how would the final layout have redundant view groups. An example to elaborate this part would be a great help. Thanks.

推荐答案

这意味着,如果在 onCreateView()返回查看无论如何都会被附加到容器视图,因此将其设置为真正 onCreateView()将导致它被两次加入到容器布局,这是不是你平时想要什么。和根视图设置为不为空,仍然有 attachToRoot 虚假夸大可以从查看根派生,W / O被添加。

It means that in case on onCreateView() returned View will be attached to container view anyway, so setting it to true in your onCreateView() would cause it to be added twice to container layout, which isn't what you usually want. And setting root view to not null and still have attachToRoot false allows inflated view to derive from root, w/o being added.

这篇关于对于混乱的Andr​​oid inflater.inflate文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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