Google maps v2 fragment of the image flickers when changing its width

My application contains a snippet of the Google maps v2 API Maps. When I click on the button, I want to change its width from left to right as follows: Google map occupies half the screen → Google map displaying the entire screen.

This works, but I see a strange black area on the right side of the screen during the transition in width. I read that this is a Google bug, and that they have released a fix for this, but it only works with Android 4.1. I am using Android 4.0

I also checked some workarounds mentioned by other people, but they all focus on tasks like scrolling, etc. No one mentions changing the width of the display of Google maps.

Can anybody help me?

My 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" />

Google maps init:

        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);

"expand" , google :

ResizeWidthAnimation anim = new ResizeWidthAnimation(mapFragment.getView (), width);
anim.setDuration(400);
mapFragment.getView ().startAnimation(anim);

:

 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;
}
}
+4
2

, . .

, Google:

  • "" "" , Google . show/hide . . :

    FragmentManager manager = getSupportFragmentManager();  
    FragmentTransaction ft1 = manager.beginTransaction();
    ft1.show (someFragment);
    ft1.hide (someFragment2);
    ft1.commit();   
    
  • Google (, , ..). () , Google, ..
+2

( ), . , , .

SurfaceView, requestTransparentRegion() MapFragment, .

0

Source: https://habr.com/ru/post/1538072/


All Articles