我的应用程序其中一个片段在表面视图中绘制了一张地图,上面覆盖了按钮和文本。
大多数其他片段都是列表。我的问题是,在地图和另一个片段之间的过渡期间,丑陋的黑色矩形会暂时出现在放置文本和按钮视图的地图视图中。这在返回地图的过渡时显得更加明显,尽管它确实发生在两个方向上。我正在使用左滑/右滑动画,它在所有其他方面都很好用。我试过其他动画,没有动画。在过渡之前将文本和按钮设置为不可见也无济于事,因为视图仍然存在于叠加层中。
如果有人对如何实现干净的片段转换有任何想法,将不胜感激。我正在使用支持片段管理器。
这是我的代码(文本和按钮比我在下面显示的要多得多):
布局xml文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapframeview"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 >
<com.mypackage.MapView 
    android:id="@+id/maptileview"  
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
</com.mypackage.MapView>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapoverlay"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >
   <TextView
    android:id="@+id/titletext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:paddingTop="10dp"
    android:textColor="#FFFFFF"
    android:textSize="24dp"
    android:textStyle="bold" />
    <ImageButton
    android:id="@+id/bookButton"
    android:onClick="onClickBookButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:paddingTop="15dp"
    android:paddingRight="15dp"
    android:background="@android:color/transparent"
    android:src="@drawable/bookbutton">
    </ImageButton>
  </RelativeLayout>
 </FrameLayout>        
片段转换代码:
 private void startNextFragment(Fragment newFragment, String fragment tag) {
FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction transaction = 
            fragmentManager.beginTransaction();
    transaction.setCustomAnimations(R.layout.slideinright,
                                        R.layout.slideoutleft,  
                                        R.layout.slideinleft, 
                                        R.layout.slideoutright);
    transaction.replace(R.id.fragment_container, newFragment, fragmentTag);
    transaction.addToBackStack(null);
    // Commit the transaction
    transaction.commit();
}
动画xml:
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/res/anim/slide_in_right.xml */
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="50%p" android:toXDelta="0"
        android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
        android:duration="@android:integer/config_mediumAnimTime" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/res/anim/slide_out_left.xml*/
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-50%p"
        android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
        android:duration="@android:integer/config_mediumAnimTime" />
</set>