android - 您如何以编程方式更改 Google Maps v2(支持 Fragment)的宽度和高度?

标签 android android-fragments android-maps-v2

如何以编程方式更改 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/

相关文章:

Android map v2 - 动画标记

android - 图形布局在带有 adt 10.1 的 Eclipse 中不起作用

android - 每 N 秒更新一次 TextView?

android - 如何通过单击选项菜单更改 MainActivity 中 webview 的 url

android - 谷歌地图 Android API v2 : Authorization Failure

Android:如何绘制从当前位置到目的地的路线方向谷歌地图 API V2

java - 多个项目使用相同的 API key

android - 无法在Android Studio中运行应用

Android Activity 和 Fragment 之间的通信

java - 添加 EditText 时 Fragment 中出现 NullPointerException