如何以编程方式更改 com.google.android.gms.maps.SupportMapFragment 的宽度和高度?我想你也许可以用 match_parent 将它包装在一个 View 组中,但如果我不需要的话,我希望不要嵌套(老实说,甚至不确定它是否有效)。
<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"
/>
为了提供上下文,我想在 map 点击时将 map 从一个高度扩展到另一个高度。
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
expandMap(); // not sure how to do this programatically.
}
});
任何帮助都会很棒!
最佳答案
我在 Programmatically set google map fragment visibility (API2) 的帮助下想通了。 .
mMapFragment = (SupportMapFragment) (getSupportFragmentManager()
.findFragmentById(R.id.storefront_map));
ViewGroup.LayoutParams params = mMapFragment.getView().getLayoutParams();
params.height = 900;
mMapFragment.getView().setLayoutParams(params);
关于android - 您如何以编程方式更改 Google Maps v2(支持 Fragment)的宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21469345/