Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
696 views
in Technique[技术] by (71.8m points)

android - How do you programmatically change the width & height of Google Maps v2 (support Fragment)?

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.
    }
});

Any help would be great!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I figured it out largely with the help of 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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...