你如何以编程方式改变宽度 &Google Maps v2 的高度(支持 Fragment)? [英] How do you programmatically change the width & height of Google Maps v2 (support Fragment)?
本文介绍了你如何以编程方式改变宽度 &Google Maps v2 的高度(支持 Fragment)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何以编程方式更改 com.google.android.gms.maps.SupportMapFragment 的宽度和高度?我想你可以用 match_parent 把它包装在一个视图组中,但我希望如果我不需要的话不要嵌套(老实说,甚至不确定它是否有效).
How do you programatically change the width and height of a com.google.android.gms.maps.SupportMapFragment? I'd imagine you might be able to wrap it in a viewgroup with match_parent, but I'm hoping not to nest if I don't have to (honestly not even sure it works).
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/storefront_map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="250dp"
/>
为了提供上下文,我想在点击地图时将地图从一个高度扩展到另一个高度.
To give context, I'd like to expand the map from one height to another on map click.
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
expandMap(); // not sure how to do this programatically.
}
});
任何帮助都会很棒!
推荐答案
我主要是在 以编程方式设置谷歌地图片段可见性 (API2).
mMapFragment = (SupportMapFragment) (getSupportFragmentManager()
.findFragmentById(R.id.storefront_map));
ViewGroup.LayoutParams params = mMapFragment.getView().getLayoutParams();
params.height = 900;
mMapFragment.getView().setLayoutParams(params);
这篇关于你如何以编程方式改变宽度 &Google Maps v2 的高度(支持 Fragment)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文