片段在背景中可见 [英] Fragment visible on the background
问题描述
我的工作有哪些是在一个XML文件中定义的三个片段的应用程序:
I am working on an application that has three fragments which are defined in an XML file:
[HeaderFragment]
[MainFragment]
[FooterFragment]
第一个屏幕启动三个片段,在报头 - 和FooterFragment是静态的,所以不会改变的内容。
The first screen initiates the three fragments, the Header- and FooterFragment are static so will not change content.
该MainFragment是最初带有按钮的菜单和TRANSPARANT背景( MenuFragment
)。当我在菜单中单击某个项目我更换 MenuFragment
用新的片段( DetailsFragment
)是这样的:
The MainFragment is initial a menu with buttons and a transparant background (MenuFragment
). When I click an item in the menu I replace the MenuFragment
with a new fragment (DetailsFragment
) like this:
FragmentTransaction transaction = mFragmentManager.beginTransaction();
Fragment newFragment = new DetailFragment();
transaction.replace(R.id.content_container, newFragment);
transaction.addToBackStack(newFragment.getTag());
transaction.commit();
的 DetailFragment
显示出来,当我preSS回来,出现 MenuFragment
和一切工作如何应该。
The DetailFragment
shows up and when I press back, the MenuFragment
appears and everything works how it should.
这是我的问题:
在我的 DetailFragment
,我有一个切换选项来筛选内容,这是一个按钮。当这个被点击, DetailFragmentFiltered
替换 DetailFragment
以同样的方式为code以上的状态。唯一的区别是,我并不因为经过过滤和pressing它添加到BackStack回..我还是想回到 MenuFragment
。
Inside my DetailFragment
, I have a toggle option to filter the content, this is a button. When this is clicked, the DetailFragmentFiltered
replaces the DetailFragment
on the same way as the code above states. The only difference is that I don't add it to the BackStack because after filtering and pressing Back.. I still want to return to the MenuFragment
.
当我点击过滤器按钮,preSS回来, DetailFragment
(或 DetailFragmentFiltered
)显示我的背后 MenuFragment
。 Afcourse,我不想这样。
When I clicked the filter button and press Back, the DetailFragment
(or DetailFragmentFiltered
) is shown behind my MenuFragment
. Afcourse, I don't want this.
推荐答案
请务必不要通过设置一个片段为使用静态片段关系到一个XML机器人:名。在布局
Make sure you don't use a static fragment relation to an XML by setting the first fragment as "android:name" in the layout.
与framelayouts使XML的布局和灵活地添加片段作为本教程中所示:
Make with framelayouts the layout of the XML and add the fragments flexibly as shown in this tutorial:
http://developer.android.com/training/basics/片段/片段ui.html
这篇关于片段在背景中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!