刷新活动的重新创建方法在谷歌地图中显示白色屏幕

时间:2016-06-10 08:49:54

标签: android google-maps android-activity fragment

我在onActivityResult中使用了一个重新创建活动生命周期的方法,以便活动刷新 我的活动一切正常,但谷歌地图显示白色屏幕! 当我转移到另一个活动并回到此活动时,地图正在加载,它的工作正常!感谢您的帮助

recreate();

我在布局中有地图片段,我使用workaroundMapFragment来自定义地图以在地图上滚动

<fragment
                android:id="@+id/view_receipt_map"
                android:name="com.receiptmatch.android.utils.WorkaroundMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
 public class WorkaroundMapFragment extends SupportMapFragment {
private OnTouchListener mListener;
View layout;
@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle savedInstance) {
     layout = super.onCreateView(layoutInflater, viewGroup, savedInstance);

    TouchableWrapper frameLayout = new TouchableWrapper(getActivity());

    frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent));

    ((ViewGroup) layout).addView(frameLayout,
            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    return layout;
}

public WorkaroundMapFragment setListener(OnTouchListener listener) {
    mListener = listener;
    return this;
}

public interface OnTouchListener {
    void onTouch();
}

public class TouchableWrapper extends FrameLayout {

    public TouchableWrapper(Context context) {
        super(context);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mListener.onTouch();
                break;
            case MotionEvent.ACTION_UP:
                mListener.onTouch();
                break;
        }
        return super.dispatchTouchEvent(event);
    }
}

}

在我的活动中

private WorkaroundMapFragment supportMapFragment;
private GoogleMap mMap;
mMap = ((WorkaroundMapFragment) getSupportFragmentManager().findFragmentById(R.id.view_receipt_map)).getMap();
supportMapFragment = ((WorkaroundMapFragment) getSupportFragmentManager().findFragmentById(R.id.view_receipt_map))
            .setListener(new WorkaroundMapFragment.OnTouchListener() {
                @Override
                public void onTouch() {
                    scrollViewRootLayout.requestDisallowInterceptTouchEvent(true);
                }
            });
onMapReady(mMap);
 @Override
public void onMapReady(GoogleMap googleMap) {
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    LatLng latLng = new LatLng(Double.valueOf(viewReceiptParser.receipt.Latitude), Double.valueOf(viewReceiptParser.receipt.Longitude));
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(latLng)
            .zoom(14)
            .build();
    googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    googleMap.addMarker(new MarkerOptions().position(latLng)/*.title(viewReceiptParser.receipt.VendorName)*/);

    googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng latLng) {
            launchGoogleMap();
        }
    });
    googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            launchGoogleMap();
            return false;
        }
    });

}

0 个答案:

没有答案