I added the controller's container to the layout. When I try to call the controller.setVisible(true) (in the touch event), I get this exception:
java.lang.RuntimeException: view android.widget.ZoomButtonsController$Container@44c1e490 being added, but it already has a parent
Here's the code to add the controller:
final TextView xView = (TextView)findViewById( R.id.xView);
final ZoomButtonsController controller = new ZoomButtonsController(xView );
ViewGroup zoomControlContainer = controller.getContainer();
LinearLayout layout = (LinearLayout) findViewById(R.id.parent_layout);
layout.addView(zoomControlContainer);
controller.setAutoDismissed(true);
Code to handle touch event:
xView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
controller.setVisible(true);
return false;
}
});
If I don't add the container, controller.setVisible(t开发者_StackOverflowrue) has no effect anyways. Any pointers?
Take a look at this question I think Mark Murphy does a good job of explaining what you should do and also how you should debug this if you are still having issues.
Take a look at this and this.
Why dont you use:
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
精彩评论