片段还是更换了背景中可见 [英] Fragment replaced still visible on background
问题描述
我想替换一个片段,一个又一个新的使用抽屉式导航模式。它似乎工作,但是当我选择从抽屉另一个选择新的片段是加载,但两个片段是可见的。我使用的不是静态的片段布局,所以我不知道问题出在哪里。
I'm trying to replace one fragment with another one using new navigation drawer pattern. It seems to work but when I choose another option from drawer the new fragment is loaded but both fragments are visible. I'm not using static fragment layout so I don't know where is the problem.
片段通过 onItemClick
法实施 AdapterView.OnItemClickListener
在我的活动加载。
Fragments are loaded through onItemClick
method implementing AdapterView.OnItemClickListener
on my activity.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Fragment fragmentToShow = null;
// Load desired fragment
switch (position) {
case 0: // Authors
if (fragmentAuthors == null) fragmentAuthors = new FragmentAuthors();
fragmentToShow = fragmentAuthors;
break;
case 1: // Books
if (fragmentBooks == null) fragmentBooks = new FragmentBooks();
fragmentToShow = fragmentBooks;
break;
}
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.ActivityMain_Drawer_FrameMain, fragmentToShow);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
mDrawerLayout.closeDrawers();
}
布局
Layout
<!-- The main content view -->
<FrameLayout
android:id="@+id/ActivityMain_Drawer_FrameMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light" />
<!-- The navigation drawer -->
<FrameLayout
android:id="@+id/ActivityMain_Drawer_FrameMenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/background_light">
<ListView
android:id="@+id/ActivityMain_Drawer_FrameMenu_List"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</FrameLayout>
截图
<一个href="https://dl.dropboxusercontent.com/u/1763308/Screenshots/device-2013-05-27-113128.png">https://dl.dropboxusercontent.com/u/1763308/Screenshots/device-2013-05-27-113128.png <一href="https://dl.dropboxusercontent.com/u/1763308/Screenshots/device-2013-05-27-113139.png">https://dl.dropboxusercontent.com/u/1763308/Screenshots/device-2013-05-27-113139.png
推荐答案
我有一些片段同样的问题。为了解决这个问题我简单的设置背景颜色,所有的分片布局,例如:
I have same issue with some fragments. To solve it I simple set background color for all fragment layouts, for example:
android:background="?android:attr/colorBackground"
这篇关于片段还是更换了背景中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!