Resizing Actual MapView - not contents in mapview

别来无恙 提交于 2019-12-12 03:12:42

问题


I'm trying to resize my MapView when a user clicks a certain button (ie - go from a mapview a quarter of the screen size to full screen size) however I do not know how to do it!

I've tried mMapView.setLayoutParams(new MapView.LayoutParams(250, 250, 0, 0, 6)); but that only gives me errors (ClassCastException).

I can't think of anything else (and searching has not come up with much).


回答1:


Try this:

        MapView map = new MapView(this, "");
        map.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
        map.setLayoutParams(new ViewGroup.LayoutParams(200, 200));

By the way as a general rule, never use absolute positioning (250 pixels) to do anything in Android - it'll cause problems when used on different devices. Use relative layouts, or at the very least device independent pixels (dip). So for example you could set the layout_width to wrap_content, the layout_weight of the MapView to 1 (so it stetches to fill the available space), and then place another UI element to its side, taking up some of the space, and the map will then reduce in size.



来源:https://stackoverflow.com/questions/9550008/resizing-actual-mapview-not-contents-in-mapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!