我的应用程序的其中一个 fragment 在表面 View 中绘制了一张 map ,上面覆盖了按钮和文本。
大多数其他 fragment 都是列表。我的问题是,在 map 和另一个 fragment 之间的过渡期间,丑陋的黑色矩形会暂时出现在放置文本和按钮 View 的 map View 中。这在返回 map 的过渡中显得更加明显,尽管它确实发生在两个方向上。我使用的是左滑/右滑动画,它在所有其他方面都运行良好。我试过其他动画,但没有动画。在过渡之前将文本和按钮设置为不可见也无济于事,因为 View 仍在叠加层中。
如果有人对如何实现干净的 fragment 过渡有任何想法,我们将不胜感激。我正在使用支持 fragment 管理器。
这是我的代码(文本和按钮比我在下面显示的要多得多):
布局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>
fragment 转换代码:
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>
最佳答案
如果您使用的是 SurfaceView,请将背景设为透明。
android:background="@android:color/transparent"
这对我有用,闪烁消失了。
关于android - 丑陋的 fragment 过渡到带有覆盖的表面 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14925060/