谷歌地图v2片段视图在更改宽度时会闪烁

use*_*943 5 java eclipse android google-maps android-fragments

我的应用包含Google maps v2 API片段视图.点击按钮我想要从左到右改变它的宽度:谷歌地图拍摄半屏 - >谷歌地图全屏显示.

它有效,但在宽度过渡期间,我在屏幕右侧看到奇怪的黑色区域.我已经读过这是谷歌的bug,并且他们已经发布了针对此的修复程序,但它仅适用于Android 4.1版本.我使用的是Android 4.0

此外,我检查了另一个人提到的一些变通方法,但他们都专注于滚动等任务.没有人提到谷歌地图视图宽度变化.

有人可以帮帮我吗?

我的xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainLayout"     
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="510dp"       
    android:layout_height="match_parent"
    android:layout_marginLeft="10dp"           
    android:layout_marginTop="10dp" />

<ImageView
    android:id="@+id/mapExpandButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="25dp"
    android:layout_marginRight="510dp"
    android:background="@drawable/map_expand" />

<ImageView
    android:id="@+id/mapCloseButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="25dp"
    android:layout_marginLeft="15dp"
    android:background="@drawable/map_close" />
Run Code Online (Sandbox Code Playgroud)

谷歌地图初始化:

        mapFragment = (SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
        map = mapFragment.getMap ();
        map.getUiSettings().setRotateGesturesEnabled(false);    // disable rotation         
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(54.6873439, 25.2770559) , 16.0f));  // set initial position         
        map.getUiSettings().setZoomControlsEnabled(false);
Run Code Online (Sandbox Code Playgroud)

在"展开"按钮单击,我正在扩展谷歌地图,如下所示:

ResizeWidthAnimation anim = new ResizeWidthAnimation(mapFragment.getView (), width);
anim.setDuration(400);
mapFragment.getView ().startAnimation(anim);
Run Code Online (Sandbox Code Playgroud)

动画类:

 public class ResizeWidthAnimation extends Animation
 {
  private int mWidth;
  private int mStartWidth;
  private View mView;

public ResizeWidthAnimation(View view, int width)
{
    mView = view;
    mWidth = width;
    mStartWidth = view.getWidth();
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
    int newWidth = mStartWidth + (int) ((mWidth - mStartWidth) * interpolatedTime);

    mView.getLayoutParams().width = newWidth;
    mView.requestLayout();

}

@Override
public void initialize(int width, int height, int parentWidth, int parentHeight)
{
    super.initialize(width, height, parentWidth, parentHeight);
}

@Override
public boolean willChangeBounds()
{
    return true;
}
}
Run Code Online (Sandbox Code Playgroud)

Bla*_*der 0

在动画的每一帧上重新布局非常昂贵(对于地图来说更是如此),您不应该这样做。如果您确实想对地图的边界进行动画处理,请尝试应用缩放动画,然后在其结束时将视图重新布局为其最终的新尺寸并禁用缩放。

要使用地图或任何其他来提高动画性能SurfaceView,您可以调用requestTransparentRegion()容器MapFragment,并将其自身作为参数传递。