chirrup

MapView layout nonsense

Discussion created by chirrup on Aug 20, 2013
Hello :)

Can someone please explain why does MapView call requestLayout() on parent (or any other method that in turn leads to requestLayout() getting called) every time you move map with touch action? Pinching it doesn't have such effect. It makes no sense knowing what requestLayout() actually does. Is it a bug?

Requesting layout leads to onMeasure() and onLayout() getting called, so this strange MapView behavior makes it impossible to use it with DrawerLayout and custom layouts (or anything that uses ViewDragHelper or offsets layout).
In addition to that, deeper view hierarchies slow everything like crazy.


public class MapActivity extends Activity {
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

  MapView map = new MapView(this);
  map.addLayer(new OpenStreetMapLayer());
  
  CustomLayout layout = new CustomLayout(this);
  layout.addView(map);
  
        setContentView(layout);
    }
    
    public static class CustomLayout extends FrameLayout {

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

  @Override
  public void requestLayout() {
       Log.d("wtf", "requestLayout()");
       super.requestLayout();
      }
    }
}

Outcomes