4

我有一个包含 MapFragment 的视图

我的 mainViewPanel 看起来像这样

<LinearLayout
android:id="@+id/main_view_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal">

<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraTargetLat="40.72"
map:cameraTargetLng="-74.00"
map:cameraZoom="8"/>

</LinearLayout>

我的翻译代码看起来像这样

TranslateAnimation anim = new TranslateAnimation(0, 500, 0, 0);
anim.setFillAfter(true);
anim.setDuration(250);
mainViewPanel.startAnimation(anim);

视图的其余部分动画,但地图保持不变。就像主视图窗口正在移动,我可以在地图右侧看到更多内容,但地图本身并没有在视觉上移动。动画适用于其他视图,如 TextView

4

2 回答 2

3

这适用于较新版本的android

mainViewPanel.animate().translationX(500);
于 2013-01-19T20:29:13.173 回答
0

这是因为新地图 api 是使用 SurfaceView 创建的,并且由于该动画不可行。

作为我发现的临时补丁是:在 MapFragment 上使用任何透明视图。因此,如果您要为 MapFragment 制作动画,它会随之制作动画,此时地图将是不可见的。

举个例子:

<RelativeLayout
android:id="@+id/main_view_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraTargetLat="40.72"
map:cameraTargetLng="-74.00"
map:cameraZoom="8"/>

 <ImageView
            android:id="@+id/map_overlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#00000000" />

</RelativeLayout>

试试这个。它应该工作。

注意:当您为视图设置动画时,您可能必须更改其可见性。如果要在动画后显示地图,则必须隐藏叠加视图,并且在要开始动画时,必须取消隐藏叠加视图。但是您必须确保只有在动画完成后才能完成隐藏/取消隐藏过程。

动画步骤

  • 在开始动画之前,取消隐藏覆盖视图
  • 动画完成后,意味着经过一段时间的延迟,隐藏覆盖视图

这个对我有用。

于 2013-03-07T14:56:42.750 回答