我可以删除一个layout.xml文件中定义的片段? [英] Can I remove a fragment defined in a layout.xml file?

查看:322
本文介绍了我可以删除一个layout.xml文件中定义的片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时才有可能FragmentTransaction和remove()方法来摆脱那些在layout.xml定义的片段(使用片段标记)使用?

Is is possible to use FragmentTransaction and the remove() method to get rid of fragments that are defined in the layout.xml (using the fragment tag) ?

我没这个使用支持库V4的工作。片段留在地方,你提交FragmentTransaction后,调用remove()之后。谁能告诉我,如果这是由设计,错误或功能?

I did not this to work using the support libraries v4. The fragment stays in place after you commit the FragmentTransaction, after calling remove(). Can anyone tell me if this is by design, a bug or a feature?

有可能替换已在lyaout.xml定义的片段,所以我觉得有些奇怪,它不应该是能够去除呢?

It is possible to replace a fragment that is defined in the lyaout.xml, so I find it a bit strange that it should not be possible to remove it?

推荐答案

开始提供蜂窝那些在支持libarary的工作是相同的,所以你不能删除已在你的布局被宣布为片段的一个实例的本地API XML文件。

The native APIs available starting in Honeycomb work the same as those in the support libarary, so you cannot remove an instance of a Fragment which has been declared in your layout XML file.

使用您操作ViewGroups FragmentTransactions如充当容器持有其他碎片的布局LinearLayouts。然而,当你声明片段在你的布局,它并没有在同一个意义上的容器,因为它是永久的景观层次结构的一部分,所以你不能去掉它。这是由设计,以支持诸如导航片段,你永远不会删除反正。 :)

With FragmentTransactions you manipulate ViewGroups such as LinearLayouts that act as containers to hold the layout of other Fragments. However, when you declare a Fragment in your layout, it doesn't have a container in the same sense because it is permanently part of the View hierarchy, so you can't remove it. That is by design, to support things like navigation Fragments that you'd never remove anyways. :)

有一件事很有趣,我发现它完全是偶然,是可以添加新片段到这是与你的布局标记声明的片段;和它作为一个容器,用于其他片段

One thing that's interesting, and I found it out totally by accident, is that you can add new Fragments into a Fragment that was declared with the tag in your layout; and it acts as a container for other Fragments

这篇关于我可以删除一个layout.xml文件中定义的片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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