【发布时间】:2013-02-02 05:16:54
【问题描述】:
我的应用程序其中一个片段在表面视图中绘制了一张地图,其中包含按钮和文本的叠加层。
大多数其他片段都是列表。我的问题是,在地图和另一个片段之间的过渡期间,丑陋的黑色矩形会暂时出现在放置文本和按钮视图的地图视图中。这在返回地图的过渡时显得更加明显,尽管它确实发生在两个方向上。我正在使用左滑/右滑动画,它在所有其他方面都很好用。我试过其他动画,没有动画。在过渡之前将文本和按钮设置为不可见也无济于事,因为视图仍然存在于叠加层中。
如果有人对如何实现干净的片段过渡有任何想法,将不胜感激。我正在使用支持片段管理器。
这是我的代码(文本和按钮比我在下面显示的要多得多):
布局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();
}
动画 xmls:
<?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>
【问题讨论】:
-
谢谢 - 这很可能是一个相关的问题,但我不认为它是重复的,因为问题与覆盖有关。没有覆盖,过渡是干净的。而且我们没有使用 Google 地图。
-
这可能都是真的,但是涉及
SurfaceView的动画效果有很长的问题历史。如果您只支持 API 级别 11+,请考虑使用TextureView,因为TextureView应该更适合动画。 -
我们必须支持 Gingerbread 这不是一个选项。此外,我们需要一个 SurfaceView 来实现完整的地图功能
标签: android overlay fragment surfaceview transition