Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 863
loeschg Avatar asked Jan 30 '14 23:01

loeschg


People also ask

How to set width height to Image view programmatically?

If you want to just fit the image in image view you can use" wrap content" in height and width property with scale-type but if you want to set manually you have to use LayoutParams. Layoutparams is efficient for setting the layout height and width programmatically.

How do I change the image size on Kotlin?

This example demonstrates how to resize Image in an Android App using Kotlin. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How to change the width of a column in Excel?

Excel Setting Column Width 1 Select one or more columns that you wish to resize. To select all columns, press Ctrl + A or click the Select All button. 2 On the Home tab, in the Cells group, click Format > Column Width. 3 In the Column width box, type the desired number, and click OK. See More....

How to dynamically set the content width of a Div?

The content width of a div can dynamically set or change using width(), innerWidth(), and outerWidth() methods depending upon the user requirement.

How to change the width of the content of an element?

Using outerWidth() method Example 1: Content Width of div using width() methodwill change the width of the content of an element excluding the padding, border, and margin of the element. HTML

How do I make a column wider or narrower?

If you want the information in all cells to be readable, you can either wrap text or adjust column width. I believe everyone knows the most common way to make a column wider or narrower by dragging the border of the column header to the right or to the left.


3 Answers

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);
like image 172
loeschg Avatar answered Oct 19 '22 06:10

loeschg


this is an example using onConfigurationChanged() method :

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.main);
    findViewById(R.id.storefront_map).getLayoutParams().width = 400;
}
like image 23
Jorgesys Avatar answered Oct 19 '22 06:10

Jorgesys


Fastest (with less code lines) way i found:

ViewGroup.MarginLayoutParams parms = (ViewGroup.MarginLayoutParams) rlLocation.getLayoutParams();
    parms.bottomMargin = 100;
    parms.topMargin = 100;
like image 45
Diogo Rosa Avatar answered Oct 19 '22 07:10

Diogo Rosa